SlideShare a Scribd company logo
JavaScript Essentials
               JQuery & AJAX
                                  Mak Bhatamrekar
                   http://github.com/makrand-bkar

                                             AJCP




http://meetup.com/my-ajcp
Atlanta Java Concept Pros
JQuery Features
Feature                     Desc

AJAX                        $.ajax(..), $.getJSON(..), $.get(..),$.post(), $.load()
                            $.ajax({url:”address”,success: “handler”}); (Base
                            method)
                            $(“#myid”).load(“address”) - loads HTML Element
DOM Manipulation / Search    $(“p.myStyle”).addClass(“BoldStyle”).show(). Easy to
                            find siblings, children, closest, nth element.


Animations / Effects        fade, show, hide,more..

Externalized Events         Events are binding happens in JS and not in html

Cross Browser Support       Supports all Major Browsers IE(>6.0), FF, Safari,Chrome

Jquery UI & Plugins         Widgets, and lots of Plugins
Why JQuery
DOM Selection
  • Uses familiar CSS Selector to find Elements.
  • CSS Selector reads from Right to Left (11.htm)
Selector                  Desc
$(“#myId”)                Selects Element with a particular ID (only one)
$(“h1”)                   Returns all the h1 elements
$(“.myClass”)             Returns all the elements that have class “myClass”
$(“headerDiv h1           Return all (span= “myClass”) elements which are inside h1 and
span.myClass”)            inturn which are inside headerDiv.
                          1.grossly formed selectors will Slower performance, good idea to
                          add a Class to Element for faster Selection
                          2.Cache the Selector in a variable if used frequently.
                               var mySel = $(“headerDiv h1 span.myclass”);
$(‘input[value=“foo”]’)   Returns the input elem whose value is foo
DOM Functions
$(“#txBox”).val() / $(“#txBox”).val(“nval”) Get or Set value of elem.e.g
                                            TxBox,Input,Button
$(“#elem”).html()/$(“#elem”).html(..)         Get or Set html of elem e.g div,p etc
$(“#e”).siblings(), .children(), .closest()   Traversing to the right Element
$(“#elem”).click(function)                    Adds click handler. Some others focus,
                                              mouseover, change
$.each(obj,function(idx,val){..});            Utilities - Iterate over each object in the
                                              elem or object.
$.trim(“obj”)                                 Utitlies – trims
$.data()                                      attaches custom data


JQuery Chaining –
$("#p1").css("color","red").slideUp(2000).slideDown(2000);
Restful AJAX – X stands for JSON
Async JavaScript and XML. Fetch data from Server Asynchronously
Advantages         • Interactive and Desktop Feel
                   • Refreshes only Data instead of Entire Page
                   • Create Server less Clients, with Cloud and Services.

Dis-Advantages     • Loose Context Browser History Fwd and Back Button
                   • JavaScript has to be enabled

REST Based Calls   GET – Fetch Records               UPDATE – Update Record
(HTTP Verbs)       POST – Create Record              DELETE – Delete record
Jquery AJAX Functions.
$.ajax{url:”addr”, success: handler,      • Base Method
inputdata })                              • Inputdata can be
                                            -- String (url encoding TBD)
function handler(data,httpStatus,req)       -- JSON literal
                                          • Other Options

$.post(), $.get()                         • Convenience /Shorthand Method for AJAX
                                            tailored to request
$.post(“addr”,success:function)           • It also supports chaining from Jquery 1.5
$.get(“addr”).success(function).error()   • $.ajax({type:”post”,options})

$(“#result”).load(url,completeFunc)       • Loads a specific page or part of the page
                                          • Internall calls $.get

$.getJSON()                               • Load JSON-encoded data from the server
                                             using a GET HTTP request.
                                          $.ajax({dataType: "json“,options})
JSONP(JSON Padding)

PROBLEM
Same origin policy of browser prevents a script loaded from one domain to make ajax
calls on another domain.
JSONP Solution - Return a JSON Object wrapped in a requested Call back. This Script
is injected on Window Object, executed .
Steps
Step1 – Ajax call is made with callback param http://query.yahooapis.com/v1?
format=json&callback=cbfunc

Step2: servers responds as cbfunc(JSON String)

Step3: Browser treats the response as a script, downloads and executes the script.
Deferred Object
• Enables to work with values that may not be immediately present like AJAX calls.
• Its like Publish/Subscribe, which allows you to perform logic when say couple of
  AJAX request are finished.
• Allows to Wait on multiple AJAX Requests
• Ability to attach Multiple Event Handlers

//Step1 : dfd = $.deferred() -- Create $.deferred() object
//Step2 : function myfunc(){ --
  if ( success) dfd.resolve() //Once function is done invoke resolve()
  else
   dfd.reject() //if failed invoke reject(), so that deferred can invoke reject stack
  return dfd.promise() //return the promise
}
//Step3 : add handlers
dfd.done() -- when call is success
dfd.fail() -- when call is failed
dfd.always – always call
Appendix
• Source code can be found on github

  – https://github.com/makrand-bkar/ajip_javascript
  – (11-*.html and 12-*.html)
  – https://github.com/makrand-bkar/RestServer
    (download the war file from /downloads)
Questions
• Why Jquery ?
• DOM Manipulations Questions
• How to Invoke Ajax()
THANK YOU

More Related Content

PPT
Asynchronous JavaScript & XML (AJAX)
PDF
Pentesting GraphQL Applications
PDF
Angular - Chapter 7 - HTTP Services
PPT
JavaScript & Dom Manipulation
PDF
Spring MVC Framework
PPTX
Html5
PPTX
A Brief Introduction to React.js
PPTX
Angular tutorial
Asynchronous JavaScript & XML (AJAX)
Pentesting GraphQL Applications
Angular - Chapter 7 - HTTP Services
JavaScript & Dom Manipulation
Spring MVC Framework
Html5
A Brief Introduction to React.js
Angular tutorial

What's hot (20)

PPT
Php with MYSQL Database
PDF
Basics of JavaScript
PPT
Introduction to Javascript
PDF
React - Introdução
PDF
Spring Framework - MVC
PPTX
React event
PDF
react redux.pdf
PDF
React JS - Introduction
KEY
JSON-LD: JSON for Linked Data
PPTX
ReactJS presentation.pptx
PPSX
Introduction to Html5
PPT
Oops concepts in php
PDF
Html,javascript & css
PPT
PHP - Introduction to PHP AJAX
PDF
Routing in NEXTJS.pdf
PPTX
Introduction to React JS for beginners | Namespace IT
PPTX
Lab #2: Introduction to Javascript
PDF
Lets make a better react form
PDF
Nodejs Explained with Examples
PDF
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
Php with MYSQL Database
Basics of JavaScript
Introduction to Javascript
React - Introdução
Spring Framework - MVC
React event
react redux.pdf
React JS - Introduction
JSON-LD: JSON for Linked Data
ReactJS presentation.pptx
Introduction to Html5
Oops concepts in php
Html,javascript & css
PHP - Introduction to PHP AJAX
Routing in NEXTJS.pdf
Introduction to React JS for beginners | Namespace IT
Lab #2: Introduction to Javascript
Lets make a better react form
Nodejs Explained with Examples
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
Ad

Viewers also liked (16)

DOCX
Jquery Ajax
PPT
jQuery Ajax
PPTX
CSS Fundamentals: selectors and Properties
PPTX
Ajax and Jquery
PDF
Javascript ajax tutorial
PPTX
Understanding Javascript AJAX - Imrokraft
PDF
CSS3, Media Queries, and Responsive Design
PDF
Javascript & Ajax Basics
PDF
CSS3 Media Queries
PPT
An Introduction to Ajax Programming
PPT
Ajax Ppt
PDF
Introduction to ajax
PPTX
JSON: The Basics
PPTX
Ajax ppt - 32 slides
PDF
Introduction to Bootstrap
PPTX
Introduction to ajax
Jquery Ajax
jQuery Ajax
CSS Fundamentals: selectors and Properties
Ajax and Jquery
Javascript ajax tutorial
Understanding Javascript AJAX - Imrokraft
CSS3, Media Queries, and Responsive Design
Javascript & Ajax Basics
CSS3 Media Queries
An Introduction to Ajax Programming
Ajax Ppt
Introduction to ajax
JSON: The Basics
Ajax ppt - 32 slides
Introduction to Bootstrap
Introduction to ajax
Ad

Similar to JavaScript JQUERY AJAX (20)

PPTX
A Rich Web experience with jQuery, Ajax and .NET
PPTX
A Rich Web Experience with jQuery, Ajax and .NET
KEY
Week 4 - jQuery + Ajax
PDF
PPTX
Ajax for dummies, and not only.
PPT
PDF
jQuery secrets
PPTX
jQuery Presentasion
PDF
XQuery Rocks
PDF
jQuery Rescue Adventure
PPTX
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
PDF
Lift 2 0
 
PDF
Ajax tutorial
PDF
Overview of The Scala Based Lift Web Framework
PDF
Scala based Lift Framework
PDF
Overview Of Lift Framework
PDF
jQuery-1-Ajax
PDF
<img src="../i/r_14.png" />
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
Week 4 - jQuery + Ajax
Ajax for dummies, and not only.
jQuery secrets
jQuery Presentasion
XQuery Rocks
jQuery Rescue Adventure
international PHP2011_Bastian Feder_jQuery's Secrets
Lift 2 0
 
Ajax tutorial
Overview of The Scala Based Lift Web Framework
Scala based Lift Framework
Overview Of Lift Framework
jQuery-1-Ajax
<img src="../i/r_14.png" />

More from Makarand Bhatambarekar (8)

PPT
Bootstrapping angular js with bower grunt yeoman
PPTX
Sprintintegration ajip
PPTX
Sonarjenkins ajip
PPT
Springaopdecoded ajip
PPT
Story ofcorespring infodeck
PPTX
Java scriptforjavadev part1
PPTX
Java scriptforjavadev part2a
PPTX
Getting Started with J2EE, A Roadmap
Bootstrapping angular js with bower grunt yeoman
Sprintintegration ajip
Sonarjenkins ajip
Springaopdecoded ajip
Story ofcorespring infodeck
Java scriptforjavadev part1
Java scriptforjavadev part2a
Getting Started with J2EE, A Roadmap

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
A Presentation on Artificial Intelligence
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Cloud computing and distributed systems.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Monthly Chronicles - July 2025
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
A Presentation on Artificial Intelligence
“AI and Expert System Decision Support & Business Intelligence Systems”
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Cloud computing and distributed systems.
Diabetes mellitus diagnosis method based random forest with bat algorithm

JavaScript JQUERY AJAX

  • 1. JavaScript Essentials JQuery & AJAX Mak Bhatamrekar http://github.com/makrand-bkar AJCP http://meetup.com/my-ajcp Atlanta Java Concept Pros
  • 2. JQuery Features Feature Desc AJAX $.ajax(..), $.getJSON(..), $.get(..),$.post(), $.load() $.ajax({url:”address”,success: “handler”}); (Base method) $(“#myid”).load(“address”) - loads HTML Element DOM Manipulation / Search $(“p.myStyle”).addClass(“BoldStyle”).show(). Easy to find siblings, children, closest, nth element. Animations / Effects fade, show, hide,more.. Externalized Events Events are binding happens in JS and not in html Cross Browser Support Supports all Major Browsers IE(>6.0), FF, Safari,Chrome Jquery UI & Plugins Widgets, and lots of Plugins
  • 4. DOM Selection • Uses familiar CSS Selector to find Elements. • CSS Selector reads from Right to Left (11.htm) Selector Desc $(“#myId”) Selects Element with a particular ID (only one) $(“h1”) Returns all the h1 elements $(“.myClass”) Returns all the elements that have class “myClass” $(“headerDiv h1 Return all (span= “myClass”) elements which are inside h1 and span.myClass”) inturn which are inside headerDiv. 1.grossly formed selectors will Slower performance, good idea to add a Class to Element for faster Selection 2.Cache the Selector in a variable if used frequently. var mySel = $(“headerDiv h1 span.myclass”); $(‘input[value=“foo”]’) Returns the input elem whose value is foo
  • 5. DOM Functions $(“#txBox”).val() / $(“#txBox”).val(“nval”) Get or Set value of elem.e.g TxBox,Input,Button $(“#elem”).html()/$(“#elem”).html(..) Get or Set html of elem e.g div,p etc $(“#e”).siblings(), .children(), .closest() Traversing to the right Element $(“#elem”).click(function) Adds click handler. Some others focus, mouseover, change $.each(obj,function(idx,val){..}); Utilities - Iterate over each object in the elem or object. $.trim(“obj”) Utitlies – trims $.data() attaches custom data JQuery Chaining – $("#p1").css("color","red").slideUp(2000).slideDown(2000);
  • 6. Restful AJAX – X stands for JSON Async JavaScript and XML. Fetch data from Server Asynchronously Advantages • Interactive and Desktop Feel • Refreshes only Data instead of Entire Page • Create Server less Clients, with Cloud and Services. Dis-Advantages • Loose Context Browser History Fwd and Back Button • JavaScript has to be enabled REST Based Calls GET – Fetch Records UPDATE – Update Record (HTTP Verbs) POST – Create Record DELETE – Delete record
  • 7. Jquery AJAX Functions. $.ajax{url:”addr”, success: handler, • Base Method inputdata }) • Inputdata can be -- String (url encoding TBD) function handler(data,httpStatus,req) -- JSON literal • Other Options $.post(), $.get() • Convenience /Shorthand Method for AJAX tailored to request $.post(“addr”,success:function) • It also supports chaining from Jquery 1.5 $.get(“addr”).success(function).error() • $.ajax({type:”post”,options}) $(“#result”).load(url,completeFunc) • Loads a specific page or part of the page • Internall calls $.get $.getJSON() • Load JSON-encoded data from the server using a GET HTTP request. $.ajax({dataType: "json“,options})
  • 8. JSONP(JSON Padding) PROBLEM Same origin policy of browser prevents a script loaded from one domain to make ajax calls on another domain. JSONP Solution - Return a JSON Object wrapped in a requested Call back. This Script is injected on Window Object, executed . Steps Step1 – Ajax call is made with callback param http://query.yahooapis.com/v1? format=json&callback=cbfunc Step2: servers responds as cbfunc(JSON String) Step3: Browser treats the response as a script, downloads and executes the script.
  • 9. Deferred Object • Enables to work with values that may not be immediately present like AJAX calls. • Its like Publish/Subscribe, which allows you to perform logic when say couple of AJAX request are finished. • Allows to Wait on multiple AJAX Requests • Ability to attach Multiple Event Handlers //Step1 : dfd = $.deferred() -- Create $.deferred() object //Step2 : function myfunc(){ -- if ( success) dfd.resolve() //Once function is done invoke resolve() else dfd.reject() //if failed invoke reject(), so that deferred can invoke reject stack return dfd.promise() //return the promise } //Step3 : add handlers dfd.done() -- when call is success dfd.fail() -- when call is failed dfd.always – always call
  • 10. Appendix • Source code can be found on github – https://github.com/makrand-bkar/ajip_javascript – (11-*.html and 12-*.html) – https://github.com/makrand-bkar/RestServer (download the war file from /downloads)
  • 11. Questions • Why Jquery ? • DOM Manipulations Questions • How to Invoke Ajax()