SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
AJAX:  The New Paradigm for Enterprise Web Applications Rizwan Ahmed
What is AJAX? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Components of AJAX ,[object Object],[object Object],[object Object],[object Object],[object Object]
Characteristics of AJAX apps ,[object Object],[object Object],[object Object],[object Object],[object Object]
AJAX Model
Sequences of AJAX vs. Traditional web model
Who is using AJAX? ,[object Object]
Who is using AJAX? ,[object Object]
Who is using AJAX? ,[object Object]
Beneath the Hood  ,[object Object],[object Object],[object Object],[object Object],[object Object]
XMLHttpRequest ,[object Object],[object Object],[object Object],[object Object]
XMLHttpRequest Properties ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
XMLHttpRequest Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Server Resource public class ServerResourceServlet extends HttpServlet { public void doGet(req, res) { String key = req.getParameter(&quot;key&quot;); …… . if (key != null) { returnXML = new StringBuffer(&quot;<returnedData>&quot;); returnXML.append(…); returnXML.append(&quot;</returnedData>&quot;); // setup the response res.setContentType(&quot;text/xml&quot;); // write out the xml string res.getWriter().write(returnXML.toString()); } } }
Callback Callback can be either discrete functions or anonymously declared. function  callback (){  if (req.readyState==4){  if (req.status == 200){ modifyHTML (…);  }  }  clear();  }
Mining the Response function  modifyHTML (){  var resp = req.responseText; var parser = new DOMParser(); var dom = parser.parseFromString(resp); var val = dom.getElementsByTagName(..); var elemId = document.getElementbyId(..); elemId.value = val[0].childNodes[0].nodeValue; ……… . }
Cross Browser Compatibility if (window.XMLHttpRequest) {  req = new XMLHttpRequest();  } else if (window.ActiveXObject) {  try { req = new ActiveXObject(Msxml2.XMLHTTP);  } catch (Exception e) { req = new  ActiveXObject(Microsoft.XMLHTTP); } }
Data Vehicles ●  XML <returnedData> <zip>29203</zip> <city>Columbia</city> <state>SC</state> </returnedData> ●  Plain Text (Custom formatted eg. CSV, HTML) returnedData;29203;Columbia;SC
Data Vehicles (cont.) ●  JavaScript Object Notation (JSON) A lightweight data format based off the JavaScript syntax.  Definitions can be included and parsed with JavaScript.  {“returnedData”:{ “ zip”: “29203”, “ city”: “Columbia”, “ state”: “SC”} }
Some AJAX Libraries ●  DoJo Toolkit  (http://dojotoolkit.org/) ●  Rico Toolkit  (http://openrico.org/) ●  DWR Toolkit  (http://getahead.org/dwr/) ●  Prototype  (http://prototypejs.org) ●  AjaxTags  (http://ajaxtags.sourceforge.net)
AJAX Libraries (cont.) DoJo Toolkit ●   DoJo is an open source DHTML toolkit written in JavaScript and include the AJAX  specific libraries dojo.io; dojo.rpc; dojo.json var key = document.getElementById(&quot;key&quot;);  dojo.io.bind ({  url: &quot;/server/resource?key=&quot;+key.value, load: function(type, data, evt) { callback(data); }, error: function(type, data, evt) { reportError(data); },  mimetype: “text/plain” });
AJAX Libraries (cont.) Rico Toolkit Rico is an open source toolkit allows for registering AJAX request handlers and HTML elements as AJAX response objects ●   ajaxEngine.registerElement (‘rHdl’,’server url’) ajaxEngine.sendRequest (‘rHdl’,’key=‘+key.value) ●  Server resource must respond with XML formatted document. Rico matches id attributes in the document with fields in the HTML form and populates it accordingly ●  No callback functions are necessary
AJAX Libraries (cont.) DWR Toolkit Direct Web Remoting is an open source AJAX framework for Java/JSP ●   DWRServlet  on the server end runs the whole show. Instantiated during application load time ●  On browser side a  JavaScript wrapper library  is created using Java’s Reflections API that mirror the server side classes ●  An XML configuration file  dwr.xml  provides the plumbing that connects the server side classes with the JavaScript
AJAX Libraries (cont.) Prototype Framework ●   Prototype is another open source framework that does AJAX requests with browser differences abstracted from user parameterString = “key=&quot; + escape(key);  new  Ajax.Request (“/server/resource&quot;, { method: &quot;get&quot;, parameters: parameterString, onSuccess: function(request) { var result = request.responseText; … .. }, onFailure: function(request) {…...} });
AJAX Libraries (cont.) Prototype Framework (cont.) ●   Prototype includes enhanced library support for JSON, DOM and other utilities ●   Prototype is largely used in conjunction with scriptaculous ●   Scriptaculous toolkit provides easy to use, cross browser JS libraries. Includes animation framework, visual effects, drag and drop features and AJAX controls
AJAX Libraries (cont.) AJAX using Custom Tags ●   Writing Ajaxian code over and over can be tedious and error prone ●   Encapsulate the functionality into a custom JSP tag for easy reuse ●   Using Tag Libraries will save time and enhance reusability and maintainability of the code ●   Consists of a TLD and Tag Support class ●   There are a number of 3 rd  party Tags that encapsulate Ajaxian functionality
AJAX Libraries (cont.) AjaxTags ●  AjaxTags is a Sourceforge project.  Allows use of AJAX with minimal effort ●  Consists of the following representative tags: Autocomplete –  Displays list of entries that match text into the autocomplete field HTML Content Replace  -  Connects a content area to an HTML onclick event Portlet –  Adds a portlet to a JSP page Select/Dropdown –  Populates a select field based on selection in another select field
AJAX Design Patterns ,[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns ,[object Object],[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object]
AJAX Design Patterns (cont.) ,[object Object],[object Object],[object Object],[object Object]
Request Management ,[object Object],[object Object],[object Object],[object Object]
Request Management ●  Most browsers have inbuilt queuing mechanisms which is not robust ●  Works well when requests are few and far in between ●  In real world requests are being sent from various parts of the application at different times ●  No control over when requests are sent or what order they should be sent
Request Management (cont.) ,[object Object],[object Object],[object Object],[object Object]
Recap ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
References ,[object Object],[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http responseNuha Noor
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slidesSmithss25
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)Arjun Shanka
 
Advanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIAdvanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIRasan Samarasinghe
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Adnan Sohail
 

Mais procurados (20)

Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http response
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Web server
Web serverWeb server
Web server
 
Web api
Web apiWeb api
Web api
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
Up to Speed on HTML 5 and CSS 3
Up to Speed on HTML 5 and CSS 3Up to Speed on HTML 5 and CSS 3
Up to Speed on HTML 5 and CSS 3
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Advanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIAdvanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST API
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Jquery
JqueryJquery
Jquery
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 

Semelhante a Ajax (20)

Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
M Ramya
M RamyaM Ramya
M Ramya
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Ajax
AjaxAjax
Ajax
 
Mashup
MashupMashup
Mashup
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax.ppt
Ajax.pptAjax.ppt
Ajax.ppt
 
Ajax
AjaxAjax
Ajax
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Copy of ajax tutorial
Copy of ajax tutorialCopy of ajax tutorial
Copy of ajax tutorial
 
CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
 

Último

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Français Patch Tuesday - Avril
Français Patch Tuesday - AvrilFrançais Patch Tuesday - Avril
Français Patch Tuesday - AvrilIvanti
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfROWELL MARQUINA
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 

Último (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Français Patch Tuesday - Avril
Français Patch Tuesday - AvrilFrançais Patch Tuesday - Avril
Français Patch Tuesday - Avril
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
QMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdfQMMS Lesson 2 - Using MS Excel Formula.pdf
QMMS Lesson 2 - Using MS Excel Formula.pdf
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 

Ajax

  • 1. AJAX: The New Paradigm for Enterprise Web Applications Rizwan Ahmed
  • 2.
  • 3.
  • 4.
  • 6. Sequences of AJAX vs. Traditional web model
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. Server Resource public class ServerResourceServlet extends HttpServlet { public void doGet(req, res) { String key = req.getParameter(&quot;key&quot;); …… . if (key != null) { returnXML = new StringBuffer(&quot;<returnedData>&quot;); returnXML.append(…); returnXML.append(&quot;</returnedData>&quot;); // setup the response res.setContentType(&quot;text/xml&quot;); // write out the xml string res.getWriter().write(returnXML.toString()); } } }
  • 15. Callback Callback can be either discrete functions or anonymously declared. function callback (){ if (req.readyState==4){ if (req.status == 200){ modifyHTML (…); } } clear(); }
  • 16. Mining the Response function modifyHTML (){ var resp = req.responseText; var parser = new DOMParser(); var dom = parser.parseFromString(resp); var val = dom.getElementsByTagName(..); var elemId = document.getElementbyId(..); elemId.value = val[0].childNodes[0].nodeValue; ……… . }
  • 17. Cross Browser Compatibility if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { req = new ActiveXObject(Msxml2.XMLHTTP); } catch (Exception e) { req = new ActiveXObject(Microsoft.XMLHTTP); } }
  • 18. Data Vehicles ● XML <returnedData> <zip>29203</zip> <city>Columbia</city> <state>SC</state> </returnedData> ● Plain Text (Custom formatted eg. CSV, HTML) returnedData;29203;Columbia;SC
  • 19. Data Vehicles (cont.) ● JavaScript Object Notation (JSON) A lightweight data format based off the JavaScript syntax. Definitions can be included and parsed with JavaScript. {“returnedData”:{ “ zip”: “29203”, “ city”: “Columbia”, “ state”: “SC”} }
  • 20. Some AJAX Libraries ● DoJo Toolkit (http://dojotoolkit.org/) ● Rico Toolkit (http://openrico.org/) ● DWR Toolkit (http://getahead.org/dwr/) ● Prototype (http://prototypejs.org) ● AjaxTags (http://ajaxtags.sourceforge.net)
  • 21. AJAX Libraries (cont.) DoJo Toolkit ● DoJo is an open source DHTML toolkit written in JavaScript and include the AJAX specific libraries dojo.io; dojo.rpc; dojo.json var key = document.getElementById(&quot;key&quot;); dojo.io.bind ({ url: &quot;/server/resource?key=&quot;+key.value, load: function(type, data, evt) { callback(data); }, error: function(type, data, evt) { reportError(data); }, mimetype: “text/plain” });
  • 22. AJAX Libraries (cont.) Rico Toolkit Rico is an open source toolkit allows for registering AJAX request handlers and HTML elements as AJAX response objects ● ajaxEngine.registerElement (‘rHdl’,’server url’) ajaxEngine.sendRequest (‘rHdl’,’key=‘+key.value) ● Server resource must respond with XML formatted document. Rico matches id attributes in the document with fields in the HTML form and populates it accordingly ● No callback functions are necessary
  • 23. AJAX Libraries (cont.) DWR Toolkit Direct Web Remoting is an open source AJAX framework for Java/JSP ● DWRServlet on the server end runs the whole show. Instantiated during application load time ● On browser side a JavaScript wrapper library is created using Java’s Reflections API that mirror the server side classes ● An XML configuration file dwr.xml provides the plumbing that connects the server side classes with the JavaScript
  • 24. AJAX Libraries (cont.) Prototype Framework ● Prototype is another open source framework that does AJAX requests with browser differences abstracted from user parameterString = “key=&quot; + escape(key); new Ajax.Request (“/server/resource&quot;, { method: &quot;get&quot;, parameters: parameterString, onSuccess: function(request) { var result = request.responseText; … .. }, onFailure: function(request) {…...} });
  • 25. AJAX Libraries (cont.) Prototype Framework (cont.) ● Prototype includes enhanced library support for JSON, DOM and other utilities ● Prototype is largely used in conjunction with scriptaculous ● Scriptaculous toolkit provides easy to use, cross browser JS libraries. Includes animation framework, visual effects, drag and drop features and AJAX controls
  • 26. AJAX Libraries (cont.) AJAX using Custom Tags ● Writing Ajaxian code over and over can be tedious and error prone ● Encapsulate the functionality into a custom JSP tag for easy reuse ● Using Tag Libraries will save time and enhance reusability and maintainability of the code ● Consists of a TLD and Tag Support class ● There are a number of 3 rd party Tags that encapsulate Ajaxian functionality
  • 27. AJAX Libraries (cont.) AjaxTags ● AjaxTags is a Sourceforge project. Allows use of AJAX with minimal effort ● Consists of the following representative tags: Autocomplete – Displays list of entries that match text into the autocomplete field HTML Content Replace - Connects a content area to an HTML onclick event Portlet – Adds a portlet to a JSP page Select/Dropdown – Populates a select field based on selection in another select field
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40. Request Management ● Most browsers have inbuilt queuing mechanisms which is not robust ● Works well when requests are few and far in between ● In real world requests are being sent from various parts of the application at different times ● No control over when requests are sent or what order they should be sent
  • 41.
  • 42.
  • 43.

Notas do Editor

  1. Assuming you have used a web browser from the last few years – IE, Firefox, Safari or Opera you’ve seen AJAX at work if you’ve ever used Google Maps, GMail or Yahoo! News. Spurred on by little known and lesser used technologies that had been included in web browsers for some time, the web in the last few years has taken a bold step forward, shattering the traditional usage model that required a full page to load every time new data or a new part of the application logic was accessed. Companies began to experiment with dynamic reloading of web pages transmitting only a small amount of data to the client resulting in faster and arguably better user experience.