Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.

Slides:



Advertisements
Similar presentations
AJAX Asynchronous JavaScript and XML. AJAX An interface that allows for the HTTP communication without page refreshment Web pages are loaded into an object.
Advertisements

9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
19-Jun-15 Ajax. The hype Ajax (sometimes capitalized as AJAX) stands for Asynchronous JavaScript And XML Ajax is a technique for creating “better, faster,
AJAX asynchronous server-client communication. Test.
XMLHttpRequest Object and XML What we should learn in this lesson –What is the XHR object? –How to create the XHR objects? –XHR object properties –XHR.
1 JavaScript & AJAX CS , Spring JavaScript.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
Interactive Web Application with AJAX
CGI and AJAX CS-260 Dick Steflik.
Ajax Basics The XMLHttpRequest Object. Ajax is…. Ajax is not…. Ajax is not a programming language. Ajax is not a programming language. Ajax is a methodology.
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
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
Ajax - Part II Communicating with the Server. Learning Objectives By the end of this lecture, you should be able to: – Describe the overview of steps.
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.
Posting XML Data From the Client to a Server Eugenia Fernandez IUPUI.
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:
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,
Random Logic l Forum.NET l AJAX Behind the buzz word Forum.NET ● January 23, 2006.
Ajax In Action The Journey into Web2.0 Presented by Eric Pascarello.
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)
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:
AJAX Asynchronous JavaScript & XML A short introduction.
SYST Web Technologies SYST Web Technologies AJAX.
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.
SE-2840 Dr. Mark L. Hornick 1 Introduction to Ajax Asynchronous Javascript And XML.
CHAPTER 13 COMMUNICATING WITH AJAX. LEARNING OBJECTIVES AJAX, which stands for Asynchronous JavaScript and XMLprovides a way for a browser to send and.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
AJAX AJAX Asynchronous JavaScript and XML --- MADHAVI
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.
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.
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.
Understanding XMLHttpRequest
Not a Language but a series of techniques
AJAX AJAX = Asynchronous JavaScript and XML.
CS 371 Web Application Programming
XMLHttp Object.
AJAX – Asynchronous JavaScript and XML
CSE 154 Lecture 11: AJAx.
AJAX and JSP ISYS 350.
CSE 154 Lecture 22: AJAX.
AJAX Robin Burke ECT 360.
JavaScript & AJAX.
JavaScript & jQuery AJAX.
Chengyu Sun California State University, Los Angeles
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
Web Technology Even Sem 2015
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
AJAX and JSP ISYS 350.
Presentation transcript:

Ajax (Asynchronous JavaScript and XML)

AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an asynchronous request is sent to a server. It assigns an event handler to intercept the response instead.  The technology is not limited to XML encoded data.

JavaScript: Building a Request (4 steps)  Step 1: Creating a XML HTTP Request object  var xmlhttp = new XMLHttpRequest();  Step 2: Specifying where and how to retrieve the resource  xmlhttp.open('GET', 'foo.jsp', true);  Step 3: Setting a function to be called when the response is returned by the server  xmlhttp.onreadystatechange = function() { // Code to handle the response here }  Step 4: Send the request  xmlhttp.send(null);  Note: Between step 2 and 3, the order is not important.

Step 1: Creating a XML HTTP Request object  Firefox, Opera, Safari, IE 7+  var xmlhttp = new XMLHttpRequest();  For earlier version if IE (< 7)  var xmlhttp = new ActiveXObject(MSXML_ProgID); where MSXML_ProgID is a string identifying the Microsoft XML Core Services (MSXML) installed on the client machine. It could be "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP", …  Note: To avoid code branching, you may want to use Sarissa ( It is an ECMAScript library acting as a cross-browser wrapper for native XML APIshttp://dev.abiss.gr/sarissa/

Step 2: Specifying what resource to retrieve var xmlhttp = new XMLHttpRequest(); xmlhttp.open(method, URL, isAsync);  method : Typically 'GET' or 'POST'  URL : Identify the resource we want to retrieve  isAsync : true  Asynchronous transmission false or omitted  Synchronous transmission  Note: This method call does not cause any connection to establish.

Step 2: Specifying what resource to retrieve  The second parameter (URL) can be a relative path or a complete URL.  By default, browsers only allow XML HTTP request to be sent to the server where the current document resides (for privacy and security reasons).  So the complete URL must have the same domain as the current document.  Method open() may also take an additional 4 th and 5 th parameters ( userid and password ). The two parameters are used to bypass HTTP authentication.

Step 3: Setting a call-back function xmlhttp.onreadystatechange = function() { // Code to handle the response here }  Each XMLHttpRequest object has a property named readyState, which holds the status of the server's response.  The event handler onreadystatechange is invoked whenever the value of readyState changes.

Step 3: Setting a call-back function Here are the possible values for the readyState property: StateDescription 0The request is not initialized 1The request has been set up 2The request has been sent 3The request is in process 4The request is complete  To only process the response when the request is completed, one could write the call-back function as xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { // Code to handle the response here }

Step 4: Send the request xmlhttp.send(payload);  Makes the connection to the URL specified in open()  If request is asynchronous, this call returns immediately. Otherwise this call blocks further execution until the requested resource has been fully downloaded.  If the request type is POST, payload (a string) will be sent as the body of the request. If nothing is to be sent or if request type is GET, then pass null to the method

Step 4: Send the request  To make a POST request, we will also need to set the "Content-type" header to let the server know how to handle the content.  e.g., to emulate form submission, we can write xmlhttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;' ); xmlhttp.send('param1=value1&param2=value2');  setRequestHeader() could also be used to set application-specific headers or override default headers.

Other XMLHttpRequest Methods  abort()  Cancel and stop the current request  getResponseHeader("header")  Returns the string value of a specified header in the response (e.g. "Content-type")  Note: The specified header is case-insensitive  getAllResponseHeaders()  Returns all headers from the response in a single string  Useful for debugging or searching for a particular string in the header

XMLHttpRequest Properties  status  The HTTP status code from the server  e.g., 200 for OK, 404 for Not Found, etc.  statusText  The text version of the status  readyState  The state of the request  0=uninitialized, 1=loading, 2=loaded, 3=interactive, and 4=complete

XMLHttpRequest Properties  responseText  Unparsed text of the response  responseXML  Response parsed into a DOM object; happens only if Content-type is text/xml.  onreadystatechange  Event handler that is called when readyState changes

function changeDisplay() { var fileTF = document.getElementById("filename"); var filename = fileTF.value; var request = new XMLHttpRequest(); request.open("GET", filename, true); request.onreadystatechange = function() { if (request.readyState == 4) { var area = document.getElementById("display"); area.innerHTML = request.responseText; } request.send(null); } File to load: Ajax example Example: Load a file and display its content in a DIV element.

Cross-site XMLHttpRequest  XMLHttpRequest object can only send request to the same website.  To access web services or retrieve data from other sites, you need to write a server side script to serve as a proxy.

References  W3C Working Drawf: The XMLHttpRequest Object   Wiki: XMLHttpRequest 