AJAX Rohan B Thimmappa. What Is AJAX? AJAX stands for Asynchronous JavaScript and XML. AJAX stands for Asynchronous JavaScript and XML. A remote scripting.

Slides:



Advertisements
Similar presentations
AJAX Compiled from “AJAX Programming” [Sang Shin]
Advertisements

9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
6/3/2015eBiquity1 Tutorial on AJAX Anubhav Kale (akale1 AT cs DOT umbc DOT edu)
AJAX asynchronous server-client communication. Test.
1 JavaScript & AJAX CS , Spring JavaScript.
Using AJAX Galip Aydin, Ahmet Sayar, and Marlon Pierce Community Grids Lab Indiana University.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Interactive Web Application with AJAX
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
PHP and AJAX ISYS 475. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net,
JavaScript & jQuery the missing manual Chapter 11
Chapter 6 JavaScript and AJAX. Objectives Explain the purpose and history of JavaScript Describe JavaScript features Explain the event-driven nature of.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
Intro to Ajax Fred Stluka Jan 25, /25/2006Intro to AjaxFred Stluka2 What is Ajax? "Asynchronous JavaScript and XML" New name for an old technique:
1 rfXcel Confidential Copyright 2007 Web Technology JavaScript 12/10/07.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
XMLHttpRequest Object When Microsoft Internet Explorer 5.0 introduced a rudimentary level of XML support, an ActiveX library called MSXML was also introduced,
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
J.Holvikivi 1 Ajax & scripts Jaana Holvikivi Metropolia.
AJAX (also known as: XMLHTTP, Remote Scripting, XMLHttpRequest, etc.) Matt Warden.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
AJAX محمد احمدی نیا 2 Of 27 What is AJAX?  AJAX = Asynchronous JavaScript and XML.  AJAX is not a new programming language, but.
AJAX Compiled from “AJAX Programming” [Sang Shin] (Asynchronous JavaScript and XML)
-By V.Gouthaman. INTRODUCTION Ajax (shorthand for asynchronous JavaScript and XML) is a group of interrelated web development techniques used on the client-side.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
SYST Web Technologies SYST Web Technologies AJAX.
Chapter 16: Ajax-Enabled Rich Internet Applications with XML and JSON TP2543 Web Programming Mohammad Faidzul Nasrudin.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
AJAX AJAX Asynchronous JavaScript and XML --- MADHAVI
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
INNOV-2: Build a Better Web Interface Using AJAX Chris Morgan Pandora Software Systems
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
 AJAX technology  Rich User Experience  Characteristics  Real live examples  JavaScript and AJAX  Web application workflow model – synchronous vs.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
A New Way To Web Applications Development Tin Htut Htut Naing Oo Myanmar Information Technology.
JavaScript and Ajax Week 10 Web site:
CITA 330 Section 10 Web Remoting Techniques. Web Remoting Web Remoting is a term used to categorize the technique of using JavaScript to directly make.
NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
National College of Science & Information Technology.
Introduction to AJAX Pat Morin COMP Outline What is AJAX? – History – Uses – Pros and Cons An XML HTTP Transaction – Creating an XMLHTTPRequest.
JavaScript and Ajax (Ajax Tutorial)
CSE 154 Lecture 11: AJAx.
Not a Language but a series of techniques
AJAX AJAX = Asynchronous JavaScript and XML.
CS 371 Web Application Programming
AJAX and REST.
XMLHttp Object.
AJAX – Asynchronous JavaScript and XML
AJAX.
AJAX.
CSE 154 Lecture 11: AJAx.
CSE 154 Lecture 22: AJAX.
AJAX Robin Burke ECT 360.
JavaScript & AJAX.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
Chengyu Sun California State University, Los Angeles
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Presentation transcript:

AJAX Rohan B Thimmappa

What Is AJAX? AJAX stands for Asynchronous JavaScript and XML. AJAX stands for Asynchronous JavaScript and XML. A remote scripting technique for quick access to server-side information. A remote scripting technique for quick access to server-side information. A combination of several technologies. A combination of several technologies.

History of AJAX The first instance of it was Microsoft’s XMLHTTP ActiveX Control for web-based access to Outlook/Exchange in 1998, around the time XML began to be taken seriously. The first instance of it was Microsoft’s XMLHTTP ActiveX Control for web-based access to Outlook/Exchange in 1998, around the time XML began to be taken seriously. As XMLHTTP matured, it was adopted by other browsers as XMLHttpRequest in their attempts to become more compatible with Internet Explorer’s proprietary features. As XMLHTTP matured, it was adopted by other browsers as XMLHttpRequest in their attempts to become more compatible with Internet Explorer’s proprietary features. Today, XMLHTTP/XMLHttpRequest is the foundation of AJAX and it is what handles the communication between the client and the server. Today, XMLHTTP/XMLHttpRequest is the foundation of AJAX and it is what handles the communication between the client and the server.

DHTML vs AJAX Dynamic HTML Dynamic HTML Client side only Client side only Commonly Used for navigation menu, forms…etc Commonly Used for navigation menu, forms…etc AJAX AJAX Client and server side Client and server side Used to enrich DHTML’s capabilities. Used to enrich DHTML’s capabilities.

Modern Examples Flickr Flickr GMail GMail Google Maps Google Maps Google Suggest Google Suggest Kayak.com Kayak.com Microsoft’s Atlas toolkit for ASP.NET 2.0 Microsoft’s Atlas toolkit for ASP.NET 2.0

How AJAX Compares To The Traditional Approach

Example

1. A client event occurs. A client event occurs.A client event occurs. User try to enter the value into the Text Field User try to enter the value into the Text Field JavaScript technology functions are called as the result of an event. In this case, the function validate() may be mapped to a onkeyup event on a link or form component. JavaScript technology functions are called as the result of an event. In this case, the function validate() may be mapped to a onkeyup event on a link or form component. This will make this Text Field call validate function each time user type value. This will make this Text Field call validate function each time user type value.

2. Creation of XMLHttpRequest object is created and configuration var req; function validate() { var idField = document.getElementById("userid"); var idField = document.getElementById("userid"); var url = "validate?id=" + escape(idField.value); var url = "validate?id=" + escape(idField.value); if (window.XMLHttpRequest) { if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req = new XMLHttpRequest(); } else if (window.ActiveXObject) { } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); req = new ActiveXObject("Microsoft.XMLHTTP"); } req.open("GET", url, true); req.open("GET", url, true); req.onreadystatechange = callback; req.onreadystatechange = callback; req.send(null); req.send(null);}

2. Creation of XMLHttpRequest object is created and configuration var req; function validate() { var idField = document.getElementById("userid"); var idField = document.getElementById("userid"); var url = "validate?id=" + escape(idField.value); var url = "validate?id=" + escape(idField.value); if (window.XMLHttpRequest) { if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req = new XMLHttpRequest(); } else if (window.ActiveXObject) { } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); req = new ActiveXObject("Microsoft.XMLHTTP"); } req.open("GET", url, true); req.open("GET", url, true); req.onreadystatechange = callback; req.onreadystatechange = callback; req.send(null); req.send(null);}

XMLHttpRequest objects if (window.XMLHttpRequest) { // For Non- IE Browser // For Non- IE Browser req = new XMLHttpRequest(); req = new XMLHttpRequest(); } else if (window.ActiveXObject) { } else if (window.ActiveXObject) { // For IE Browser // For IE Browser req = new ActiveXObject("Microsoft.XMLHTTP"); req = new ActiveXObject("Microsoft.XMLHTTP"); }

Open function req.open("GET", url, true); req.open("GET", url, true); The open function requires three arguments: The open function requires three arguments: the HTTP method, which is GET or POST; the HTTP method, which is GET or POST; The URL of the server-side component that the object will interact with; The URL of the server-side component that the object will interact with; boolean indicating whether or not the call will be made asynchronously. boolean indicating whether or not the call will be made asynchronously.

3. XMLHttpRequest object makes a call. req.send(null); When the statement req.send(null); is reached, the call will be made. In the case of an HTTP GET, this content may be null or left blank. The data that is posted (id) is included as a URL parameter. An HTTP POST requires a Content-Type header to be set on the XMLHttpRequest object by using the following statement: req.setRequestHeader("Content-Type", "application/x- www-form-urlencoded"); req.send("id=" + escape(idTextField.value));

4.The request is processed by the ValidateServlet. public class ValidateServlet extends HttpServlet { private ServletContext context; private HashMap users = new HashMap(); public void init(ServletConfig config) throws ServletException { this.context = config.getServletContext(); users.put("greg","account data"); users.put("duke","account data"); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String targetId = request.getParameter("id"); \* valid *\ if ((targetId != null) && !users.containsKey(targetId.trim())) { response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write("valid"); } else { } else { response.setContentType("text/xml"); response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write("invalid"); response.getWriter().write("invalid"); } } }

5.Callback() function and processes the result. req.onreadystatechange = callback; function callback() { if (req.readyState == 4) { if (req.readyState == 4) { if (req.status == 200) { var message =req.responseXML.getElementsByTagName("message")[0]; return message; return message; } } } }

XMLHttpRequest Properties onreadystatechange – This is a method delegate for a function that handles the processing of the HTTP transaction as well as the response text or XML. onreadystatechange – This is a method delegate for a function that handles the processing of the HTTP transaction as well as the response text or XML. readyState – The state of the transaction readyState – The state of the transaction 0 – uninitialized 0 – uninitialized 1 – loading 1 – loading 2 – loaded 2 – loaded 3 – interactive 3 – interactive 4 – complete 4 – complete status – The HTTP response code for the operation. All processing should occur when this flag is equal to 200 only. Error handling should be invoked on either 404 or 500. status – The HTTP response code for the operation. All processing should occur when this flag is equal to 200 only. Error handling should be invoked on either 404 or 500. statusText – The text that explains the status code. statusText – The text that explains the status code. responseText – The text of the response from the server. responseText – The text of the response from the server. responseXML – If XML is sent back by the server, you may handle the response as a XML document using this property which returns a DOM tree of the responseText. responseXML – If XML is sent back by the server, you may handle the response as a XML document using this property which returns a DOM tree of the responseText.

A Quick Recap To Using XMLHttpRequest Create a function that returns a XMLHttpRequest/XMLHTTP object appropriate for the browser in use. Create a function that returns a XMLHttpRequest/XMLHTTP object appropriate for the browser in use. Create a function for processing the response XML from the server. Create a function for processing the response XML from the server. Associate your XMLHttpRequest instance’s onreadystatechange delegate with your function. Ex: httpRequest.onreadystatechange = applyChanges; Associate your XMLHttpRequest instance’s onreadystatechange delegate with your function. Ex: httpRequest.onreadystatechange = applyChanges; Use the open method to connect to the server. Use the open method to connect to the server. Use the send method to do a transaction. Use the send method to do a transaction. If POST, the parameter must be a proper POST string such as, var1=1&var2=2&var3=3 If POST, the parameter must be a proper POST string such as, var1=1&var2=2&var3=3 If GET, “” and null may be passed since parameters will have to be passed as part of the URL. If GET, “” and null may be passed since parameters will have to be passed as part of the URL. When you need to repeat, reinitialize the XMLHttpRequest and reset its onreadystatechange delegate. When you need to repeat, reinitialize the XMLHttpRequest and reset its onreadystatechange delegate.

How to best use AJAX Use it for small updates to the web page. Use it for small updates to the web page. Build as much of the user interface for the web page statically as possible in order to limit how many AJAX calls are needed. Build as much of the user interface for the web page statically as possible in order to limit how many AJAX calls are needed.

How Not To Use AJAX Each AJAX operation causes a new HTTP transaction so overuse can quickly bring down a heavily trafficked webserver. Each AJAX operation causes a new HTTP transaction so overuse can quickly bring down a heavily trafficked webserver. Don’t use it where it makes more sense to submit a form. Don’t use it where it makes more sense to submit a form. Don’t use it for calculations and interface updates that can be done with client-side operations only. Don’t use it for calculations and interface updates that can be done with client-side operations only.

Simple Ways To Use AJAX.NET.NET Microsoft’s Atlas Toolkit Microsoft’s Atlas Toolkit Java Java AjaxAnywhere AjaxAnywhere AjaxTags AjaxTags Ruby Ruby Ruby On Rails Ruby On Rails Python Python TurboGears TurboGears PHP PHP Sajax Sajax HTML_AJAX (In the PEAR Repository) HTML_AJAX (In the PEAR Repository)

More Information And Credits Read the following for more information: Read the following for more information: php 85.php 85.php 85.php Figure on slide 5 taken from fig1.png Figure on slide 5 taken from fig1.png