SlideShare a Scribd company logo
Basic Ajax What is Ajax? Ajax Technology Where to use Ajax How to use Ajax Problems with Ajax
What is Ajax? Something everyone is talking about.   but doesn't understand
What is Ajax? The technological foundation of Web 2.0   ... but probably not socialism
What is Ajax? A heroically heroic hero   That has breathed life into JavaScript
What is Ajax? A synchronous   J avaScript   A nd   X ML Represents interrelated technologies JavaScript Asynchronous HTTP requests XML But the term has expanded to include the technologies surrounding Rich Internet Applications in general: JSON CSS HTML DOM
Ajax Technology Web class 99  JavaScript XML JSON CSS HTML DOM Web class 00 JavaScript XML JSON CSS HTML DOM Asynchronous HTTP
Ajax Technology: XMLHttpRequest Gives JavaScript the ability to asynchronously perform  Http requests Will be called XHR from now on.
Ajax Technology: XMLHttpRequest
var request = new XMLHttpRequest(); request.onreadystatechange = function(){ if(request.readyState == 4) document.getElementById(“response”).innerHTML =  request.responseText } request.open('POST', '/recipes.xml', true); request.setRequestHeader('Content-Type',  'application/x-www-form-urlencoded'); request.send('recipe[title]=Ice+Water&'+ 'recipe[instructions]=Pour+ice+and+water+in+glass'); Ajax Technology: XMLHttpRequest Create a new recipe and put result HTML in 'response' element.
jQuery jQuery.post( url, [data], [callback], [type] )   jQuery.post( “ /recipes.xml”, { “ recipe[title]” : “Ice Water”, “ recipe[instructions]” : “Pour ice and water in glass”  }, function(html){ $(“#response”).text(html)  },  “ html”  )
Prototype new Ajax.Request(url[, options]) new Ajax.Request (“/recipes.xml”,{ parameters :{ “ recipe[title]” : “Ice Water”, “ recipe[instructions]” : “Pour ice and water in glass”  }, onComplete: function(request){  $(“response”).update(request.innerHTML)  },  method: “post” })
YUI YAHOO.util.Connect.asyncRequest(method, sUrl, callbacks, data); YAHOO.util.Connect.asyncRequest ( “ POST” “ /recipes.xml”, { onSuccess :  function(event,args){  document.getElementById(“response”) =  args[0].responseText  } }, { “ recipe[title]” : “Ice Water”, “ recipe[instructions]” : “Pour ice and water in glass”  }  )
Dojo dojo.io.bind([options]) dojo.io.bind({ method: “POST”, url: “/recipes.xml”, load: function(data){    dojo.byId("title").innerHTML = data;  }, content: { “ recipe[title]” : “Ice Water”, “ recipe[instructions]” : “Pour ice and water in glass”  }  )
Benefits of Ajax Makes your web applications More responsive Reduce bandwidth More interactive Make use of more complex UI state.
Typical Use Cases Use where traditional web applications require a page change,  but new page looks almost identical. Adding or removing items from a list. Showing more details. Examples:
How to use Ajax Ajax is typically used to get and manipulate data.  Typically the data comes back in one of two ways: Data Text XML JSON Markup HTML HTML+JS Yeah well that's just,  like, your opinion, man.   Enables services JSON on both sides Faster  Send Data and use JSON
Ajax Issues Ajax makes some things more difficult Back Button / History / Bookmarking Duplicate code on the client and server Clients without JavaScript / Web Search Engines Testing Does not support cross domain requests Ajax and JavaScript share many of the same problems.
Ajax Issues Back Button / History / Bookmarking  Problem:  Browser does not capture page changes due to JavaScript. Solution:   Use a library like Really Simple History (RSH).  RSH uses a hidden iframe and changes of the url hash to let JS provide its own history. http://code.google.com/p/reallysimplehistory/
Ajax Issues Duplicate code on the client and server Problem:  Often similar code must be present client and server side which adds to the complexity of the application.  Typically this is markup generation. Solution:   1) Send back markup generated by the Server. 2) Server never creates markup.  Use client side templates to generate  markup.  Dojo Django templates JavaScriptMVC EJS templates jQuery templates
Ajax Issues Clients without JavaScript / Search Engines Problem:  Some people turn off JavaScript.  Most search engines don't understand JavaScript. Solution:   1) Ignore.  95% have JavaScript.  Many popular websites require it. 2) Develop unobtrusively. 3) Use Rhino server side to generate the pages.
Ajax Issues Developing unobtrusively Rules: 1.  Assume client has JavaScript turned off. 2. JavaScript prevents default behavior from happening 3. JavaScript substitutes its own Ajax behavior
Ajax Issues Developing unobtrusively Example : 1.  Create a form that on submit adds an item to a shopping cart. <form id='add' action=”add_to_cart”> <input type='hidden' name=”item” value=”2”> <input type=”submit” value=”add to cart”> </form> 2.  Use JS to cancel the submit event. $(“#add”).submit(function(){ return false; }) 3.  Perform the request, and update the shopping cart total. $(“#add”).submit(function(){  jQuery.post(“ajax_add_to_cart”, {name: this.item.value }, function(html){ $(“#total”).text(html)}, “ html” ) return false;  })
Ajax Issues Testing Problem:  The lack of good automated testing support for JavaScript applications. Solution:   1) Server side frameworks. 2) Client side testing 3) Rhino based client testing 4) Selenium
Ajax Issues Does not support cross domain requests Problem:  The Same Origin Policy prevents XHR from making requests to other domains.  This prevents it from being used in mashups. Solution:   1) Wait 2) JSONP 3) window.name 4) Proxy

More Related Content

PDF
Dan Webb Presentation
PDF
Unobtrusive JavaScript
PPT
PPTX
Enough with the javas cript already! de Nicholas Zakas
 
PDF
The Future of CSS with Web Components
PDF
Our application got popular and now it breaks
PDF
22 j query1
PDF
Html server control - ASP. NET with c#
Dan Webb Presentation
Unobtrusive JavaScript
Enough with the javas cript already! de Nicholas Zakas
 
The Future of CSS with Web Components
Our application got popular and now it breaks
22 j query1
Html server control - ASP. NET with c#

What's hot (20)

PPTX
Ajax Technology
PDF
Intro to React - Featuring Modern JavaScript
PDF
Beyond HTML: Tools for Building Web 2.0 Apps
PDF
Web Components + Backbone: a Game-Changing Combination
PDF
HTML5 - The 2012 of the Web - Adobe MAX
PDF
Introduction to Polymer
PDF
JavaScript - Chapter 11 - Events
PPT
mukesh
PDF
A brave new web - A talk about Web Components
PDF
Web Components: The future of Web Application Development
PDF
The Art of AngularJS in 2015 - Angular Summit 2015
PPT
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
 
DOC
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
PDF
Introduction to HTML5
PDF
Ajax
PPTX
JavaServer Pages
PPTX
ASP.NET MVC and ajax
PDF
iPhone Appleless Apps
KEY
Eu odeio OpenSocial
PDF
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Ajax Technology
Intro to React - Featuring Modern JavaScript
Beyond HTML: Tools for Building Web 2.0 Apps
Web Components + Backbone: a Game-Changing Combination
HTML5 - The 2012 of the Web - Adobe MAX
Introduction to Polymer
JavaScript - Chapter 11 - Events
mukesh
A brave new web - A talk about Web Components
Web Components: The future of Web Application Development
The Art of AngularJS in 2015 - Angular Summit 2015
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
 
HTTP REQUEST RESPONSE OBJECT - WEB APPLICATION USING C# LAB
Introduction to HTML5
Ajax
JavaServer Pages
ASP.NET MVC and ajax
iPhone Appleless Apps
Eu odeio OpenSocial
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Ad

Similar to Ajax3 (20)

PPT
jQuery Ajax
PPT
Using Ajax In Domino Web Applications
PDF
Introduction to AJAX
PPT
Ajax presentation
PPT
Ajax
PPT
PDF
Ajax
PPT
AJAX
PPT
Ajax
PDF
TXT
25250716 seminar-on-ajax text
PPT
Ajax Presentation
PPTX
Ajax
PDF
Ajax tutorial
PPT
Mashup
PPT
AJAX
PPT
CTS Conference Web 2.0 Tutorial Part 2
PPT
PPT
Ajax and PHP
jQuery Ajax
Using Ajax In Domino Web Applications
Introduction to AJAX
Ajax presentation
Ajax
Ajax
AJAX
Ajax
25250716 seminar-on-ajax text
Ajax Presentation
Ajax
Ajax tutorial
Mashup
AJAX
CTS Conference Web 2.0 Tutorial Part 2
Ajax and PHP
Ad

More from Brian Moschel (12)

KEY
A Very Biased Comparison of MVC Libraries
PPTX
FuncUnit
PDF
Bottom Up
PDF
Headless Js Testing
PPTX
Comet: an Overview and a New Solution Called Jabbify
PDF
Web 2.0 Expo Notes
PDF
Comet, Simplified, with Jabbify Comet Service
PDF
Building an App with jQuery and JAXER
PPT
JavaScript Functions
ODP
Basic inheritance in JavaScript
PDF
Things to avoid in JavaScript
PDF
Javascript and DOM
A Very Biased Comparison of MVC Libraries
FuncUnit
Bottom Up
Headless Js Testing
Comet: an Overview and a New Solution Called Jabbify
Web 2.0 Expo Notes
Comet, Simplified, with Jabbify Comet Service
Building an App with jQuery and JAXER
JavaScript Functions
Basic inheritance in JavaScript
Things to avoid in JavaScript
Javascript and DOM

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
DOCX
The AUB Centre for AI in Media Proposal.docx
 
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
 
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Big Data Technologies - Introduction.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The AUB Centre for AI in Media Proposal.docx
 
Programs and apps: productivity, graphics, security and other tools
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Advanced methodologies resolving dimensionality complications for autism neur...
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation_ Review paper, used for researhc scholars
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
 
MIND Revenue Release Quarter 2 2025 Press Release

Ajax3

  • 1. Basic Ajax What is Ajax? Ajax Technology Where to use Ajax How to use Ajax Problems with Ajax
  • 2. What is Ajax? Something everyone is talking about. but doesn't understand
  • 3. What is Ajax? The technological foundation of Web 2.0 ... but probably not socialism
  • 4. What is Ajax? A heroically heroic hero That has breathed life into JavaScript
  • 5. What is Ajax? A synchronous J avaScript A nd X ML Represents interrelated technologies JavaScript Asynchronous HTTP requests XML But the term has expanded to include the technologies surrounding Rich Internet Applications in general: JSON CSS HTML DOM
  • 6. Ajax Technology Web class 99 JavaScript XML JSON CSS HTML DOM Web class 00 JavaScript XML JSON CSS HTML DOM Asynchronous HTTP
  • 7. Ajax Technology: XMLHttpRequest Gives JavaScript the ability to asynchronously perform Http requests Will be called XHR from now on.
  • 9. var request = new XMLHttpRequest(); request.onreadystatechange = function(){ if(request.readyState == 4) document.getElementById(“response”).innerHTML = request.responseText } request.open('POST', '/recipes.xml', true); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); request.send('recipe[title]=Ice+Water&'+ 'recipe[instructions]=Pour+ice+and+water+in+glass'); Ajax Technology: XMLHttpRequest Create a new recipe and put result HTML in 'response' element.
  • 10. jQuery jQuery.post( url, [data], [callback], [type] ) jQuery.post( “ /recipes.xml”, { “ recipe[title]” : “Ice Water”, “ recipe[instructions]” : “Pour ice and water in glass” }, function(html){ $(“#response”).text(html) }, “ html” )
  • 11. Prototype new Ajax.Request(url[, options]) new Ajax.Request (“/recipes.xml”,{ parameters :{ “ recipe[title]” : “Ice Water”, “ recipe[instructions]” : “Pour ice and water in glass” }, onComplete: function(request){ $(“response”).update(request.innerHTML) }, method: “post” })
  • 12. YUI YAHOO.util.Connect.asyncRequest(method, sUrl, callbacks, data); YAHOO.util.Connect.asyncRequest ( “ POST” “ /recipes.xml”, { onSuccess : function(event,args){ document.getElementById(“response”) = args[0].responseText } }, { “ recipe[title]” : “Ice Water”, “ recipe[instructions]” : “Pour ice and water in glass” } )
  • 13. Dojo dojo.io.bind([options]) dojo.io.bind({ method: “POST”, url: “/recipes.xml”, load: function(data){ dojo.byId(&quot;title&quot;).innerHTML = data; }, content: { “ recipe[title]” : “Ice Water”, “ recipe[instructions]” : “Pour ice and water in glass” } )
  • 14. Benefits of Ajax Makes your web applications More responsive Reduce bandwidth More interactive Make use of more complex UI state.
  • 15. Typical Use Cases Use where traditional web applications require a page change, but new page looks almost identical. Adding or removing items from a list. Showing more details. Examples:
  • 16. How to use Ajax Ajax is typically used to get and manipulate data. Typically the data comes back in one of two ways: Data Text XML JSON Markup HTML HTML+JS Yeah well that's just, like, your opinion, man. Enables services JSON on both sides Faster Send Data and use JSON
  • 17. Ajax Issues Ajax makes some things more difficult Back Button / History / Bookmarking Duplicate code on the client and server Clients without JavaScript / Web Search Engines Testing Does not support cross domain requests Ajax and JavaScript share many of the same problems.
  • 18. Ajax Issues Back Button / History / Bookmarking Problem: Browser does not capture page changes due to JavaScript. Solution: Use a library like Really Simple History (RSH). RSH uses a hidden iframe and changes of the url hash to let JS provide its own history. http://code.google.com/p/reallysimplehistory/
  • 19. Ajax Issues Duplicate code on the client and server Problem: Often similar code must be present client and server side which adds to the complexity of the application. Typically this is markup generation. Solution: 1) Send back markup generated by the Server. 2) Server never creates markup. Use client side templates to generate markup. Dojo Django templates JavaScriptMVC EJS templates jQuery templates
  • 20. Ajax Issues Clients without JavaScript / Search Engines Problem: Some people turn off JavaScript. Most search engines don't understand JavaScript. Solution: 1) Ignore. 95% have JavaScript. Many popular websites require it. 2) Develop unobtrusively. 3) Use Rhino server side to generate the pages.
  • 21. Ajax Issues Developing unobtrusively Rules: 1. Assume client has JavaScript turned off. 2. JavaScript prevents default behavior from happening 3. JavaScript substitutes its own Ajax behavior
  • 22. Ajax Issues Developing unobtrusively Example : 1. Create a form that on submit adds an item to a shopping cart. <form id='add' action=”add_to_cart”> <input type='hidden' name=”item” value=”2”> <input type=”submit” value=”add to cart”> </form> 2. Use JS to cancel the submit event. $(“#add”).submit(function(){ return false; }) 3. Perform the request, and update the shopping cart total. $(“#add”).submit(function(){ jQuery.post(“ajax_add_to_cart”, {name: this.item.value }, function(html){ $(“#total”).text(html)}, “ html” ) return false; })
  • 23. Ajax Issues Testing Problem: The lack of good automated testing support for JavaScript applications. Solution: 1) Server side frameworks. 2) Client side testing 3) Rhino based client testing 4) Selenium
  • 24. Ajax Issues Does not support cross domain requests Problem: The Same Origin Policy prevents XHR from making requests to other domains. This prevents it from being used in mashups. Solution: 1) Wait 2) JSONP 3) window.name 4) Proxy

Editor's Notes

  • #2: Challenges * back button * more javascript (speed concerns w/ files) * SEO