SlideShare une entreprise Scribd logo
1  sur  12
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

Contenu connexe

Tendances

Tendances (20)

ES6 presentation
ES6 presentationES6 presentation
ES6 presentation
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
jQuery
jQueryjQuery
jQuery
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-Assured
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
API Testing following the Test Pyramid
API Testing following the Test PyramidAPI Testing following the Test Pyramid
API Testing following the Test Pyramid
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
Meetup angular http client
Meetup angular http clientMeetup angular http client
Meetup angular http client
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Spring Core
Spring CoreSpring Core
Spring Core
 
[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
React js t2 - jsx
React js   t2 - jsxReact js   t2 - jsx
React js t2 - jsx
 
Mockito a simple, intuitive mocking framework
Mockito   a simple, intuitive mocking frameworkMockito   a simple, intuitive mocking framework
Mockito a simple, intuitive mocking framework
 
Expressjs
ExpressjsExpressjs
Expressjs
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 

En vedette

Javascript ajax tutorial
Javascript ajax tutorialJavascript ajax tutorial
Javascript ajax tutorial
Vlad Posea
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
Richard Paul
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
hchen1
 

En vedette (15)

Jquery Ajax
Jquery AjaxJquery Ajax
Jquery Ajax
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
CSS Fundamentals: selectors and Properties
CSS Fundamentals: selectors and PropertiesCSS Fundamentals: selectors and Properties
CSS Fundamentals: selectors and Properties
 
Javascript ajax tutorial
Javascript ajax tutorialJavascript ajax tutorial
Javascript ajax tutorial
 
Understanding Javascript AJAX - Imrokraft
Understanding Javascript AJAX - ImrokraftUnderstanding Javascript AJAX - Imrokraft
Understanding Javascript AJAX - Imrokraft
 
CSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive DesignCSS3, Media Queries, and Responsive Design
CSS3, Media Queries, and Responsive Design
 
Javascript & Ajax Basics
Javascript & Ajax BasicsJavascript & Ajax Basics
Javascript & Ajax Basics
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 

Similaire à JavaScript JQUERY AJAX

Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
baygross
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Lift 2 0
Lift 2 0Lift 2 0
Lift 2 0
SO
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
Kat Roque
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
IndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
vhazrati
 
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptxMicrosoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 

Similaire à JavaScript JQUERY AJAX (20)

A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NET
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
jQuery
jQueryjQuery
jQuery
 
Ajax for dummies, and not only.
Ajax for dummies, and not only.Ajax for dummies, and not only.
Ajax for dummies, and not only.
 
Jquery 4
Jquery 4Jquery 4
Jquery 4
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
XQuery Rocks
XQuery RocksXQuery Rocks
XQuery Rocks
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
jQuery
jQueryjQuery
jQuery
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
Lift 2 0
Lift 2 0Lift 2 0
Lift 2 0
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
J query training
J query trainingJ query training
J query training
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptxMicrosoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
Microsoft PowerPoint - <b>jQuery</b>-1-Ajax.pptx
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 

Plus de Makarand Bhatambarekar (8)

Bootstrapping angular js with bower grunt yeoman
Bootstrapping angular js with bower grunt yeomanBootstrapping angular js with bower grunt yeoman
Bootstrapping angular js with bower grunt yeoman
 
Sprintintegration ajip
Sprintintegration ajipSprintintegration ajip
Sprintintegration ajip
 
Sonarjenkins ajip
Sonarjenkins ajipSonarjenkins ajip
Sonarjenkins ajip
 
Springaopdecoded ajip
Springaopdecoded ajipSpringaopdecoded ajip
Springaopdecoded ajip
 
Story ofcorespring infodeck
Story ofcorespring infodeckStory ofcorespring infodeck
Story ofcorespring infodeck
 
Java scriptforjavadev part1
Java scriptforjavadev part1Java scriptforjavadev part1
Java scriptforjavadev part1
 
Java scriptforjavadev part2a
Java scriptforjavadev part2aJava scriptforjavadev part2a
Java scriptforjavadev part2a
 
Getting Started with J2EE, A Roadmap
Getting Started with J2EE, A RoadmapGetting Started with J2EE, A Roadmap
Getting Started with J2EE, A Roadmap
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Dernier (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

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()