1 / 14

AJAX

AJAX. Bharat chaitanya. What is AJAX ?. A synchronous J avaScript a nd X ML is a combination of standard Web technologies for the browser based web applications. JavaScript, CSS, DOM, XML It provides seamless interactivity in browser clients. No browser reloads

louisa
Download Presentation

AJAX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AJAX Bharat chaitanya

  2. What is AJAX ? • Asynchronous JavaScript and XML is a combination of standard Web technologies for the browser based web applications. • JavaScript, CSS, DOM, XML • It provides seamless interactivity in browser clients. • No browser reloads • Much smoother than standard request-wait-response for browser forms.

  3. Main Idea • AJAX’s key concept is the use of XMLHttpRequest to buffer requests and responses within the browser. • Use XMLHttpRequest to make a call to the server and get back the response without displaying it. • The response is stored locally as either plain text (plain or HTML), or XML. • JavaScript + DOM can be used to walk the HTML or XML tree to handle most user interactions.

  4. AJAX –Cont • AJAX is combination of several technologies: • For binding and user interaction -JavaScript • For styling - XHTML and CSS • For returned document handling -Document Object Model (DOM) • For data manipulation and conversion -XML and XSLT • For asynchronous data retrieval -XMLHttpRequest

  5. XmlHttpRequest (XHR) • An API that can be used by JavaScript, and other web browser scripting languages to transfer XML and other text data to and from a web server using HTTP. • Besides XML, XMLHttpRequest can be used to fetch data in other formats such as HTML or plain text. • XMLHttpRequest is an important part of the Ajax web development technique. It is used to create responsive and dynamic web applications.

  6. AJAX Frameworks • Toolkits to ease Ajax development. • Focus solely on the client side, providing easy ways to add visual effects to your pages or streamlining the use of XMLHttpRequest. • Taconite • DOJO • Scriptaculous • High-level approach to Ajax development.

  7. AJAX Applications • Google Maps • Gmail • Meebo

  8. Pros and cons • Pros • Asynchronous calls to a web server • Open standards • Bandwidth usage • Cons • Browser integration • Reliance on JavaScript • Order of XMLHttpRequests

  9. DEMO

  10. AJAX code // code for Mozilla, Opera, Safari if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } // code for IE else if (window.ActiveXObject) { try { // For versions later than 5.0 req=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { // For previous versions req = new ActiveXObject("Microsoft.XMLHTTP"); } } req.open("GET", url, true); // true=script continues to run without waiting for response req.onreadystatechange = callback; //must when true req.send(null);

  11. Servlet String targetId = request.getParameter("id"); if (targetId.equals("bharat")) { response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write("<message>valid</message>"); } else { response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write("<message>invalid</message>"); }

  12. AJAX Code function callback() { // readyState of 4 signifies request is complete if (req.readyState == 4) { // status of 200 signifies successful HTTP call if (req.status == 200) { parseMessage(); } } }

  13. AJAX Code function parseMessage() { var message = req.responseXML.getElementsByTagName("message")[0]; setMessage(message.childNodes[0].nodeValue); } function setMessage(message) { var mdiv = document.getElementById("userIdMessage"); if (message == "invalid") { mdiv.innerHTML = "<div style=\"color:red\">Invalid User Id</ div>"; } else { mdiv.innerHTML = "<div style=\"color:green\">Valid User Id</ div>"; } }

More Related