Understanding XMLHttpRequest

Slides:



Advertisements
Similar presentations
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
Advertisements

AJAX asynchronous server-client communication. Test.
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.
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,
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.
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.
Ajax In Action The Journey into Web2.0 Presented by Eric Pascarello.
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:
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 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
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.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
AJAX AJAX Asynchronous JavaScript and XML --- MADHAVI
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
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.
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
DYNAMIC WEB PAGES Dr Mohd Soperi Mohd Zahid Semester /16.
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.
Introduction to AJAX Pat Morin COMP Outline What is AJAX? – History – Uses – Pros and Cons An XML HTTP Transaction – Creating an XMLHTTPRequest.
Internet Technologies
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.
AJAX and REST.
Callback Function function passed as a parameter to another function
XMLHttp Object.
Web System & Technology
AJAX (Asynchronous JavaScript and XML.)
CSE 154 Lecture 11: AJAx.
AJAX and JSP ISYS 350.
Web-Technology Lecture 10.
CSE 154 Lecture 22: AJAX.
JavaScript & AJAX.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
Web Programming Language
RPi 2/3 GPIO + Web(Flask)
2017, Fall Pusan National University Ki-Joune Li
RESTful Web Services.
Chengyu Sun California State University, Los Angeles
Lecture 12: The Fetch Api and AJAx
AJAX CS-422 Dick Steflik.
Lecture 12: The Fetch Api and AJAx
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.
PHP and JSON Topics Review JSON.
What is AJAX? AJAX is a developer's dream, because you can:
AJAX By Prof. B.A.Khivsara
Presentation transcript:

Understanding XMLHttpRequest An object of XMLHttpRequest is used for asynchronous communication between client and server. It performs following operations: Sends data from the client in the background Receives the data from the server Updates the webpage without reloading it. All modern browsers support the XMLHttpRequest object. The XMLHttpRequest object is used to exchange data with a server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

Properties of XMLHttpRequest object The common properties of XMLHttpRequest object are as follows: Property Description onReadyStateChange It is called whenever readystate attribute changes. It must not be used with synchronous requests. readyState represents the state of the request. It ranges from 0 to 4. 0 UNOPENED open() is not called. 1 OPENED open is called but send() is not called. 2 HEADERS_RECEIVED send() is called, and headers and status are available. 3 LOADING Downloading data; responseText holds the data. 4 DONE The operation is completed fully. reponseText returns response as text. responseXML returns response as XML

Methods of XMLHttpRequest object The important methods of XMLHttpRequest object are as follows: Method Description void open(method, URL) opens the request specifying get or post method and url. void open(method, URL, async) same as above but specifies asynchronous or not. void open(method, URL, async, username, password) same as above but specifies username and password. void send() sends get request. void send(string) send post request. setRequestHeader(header,value) it adds request headers.

Create an XMLHttpRequest Object variable = new XMLHttpRequest(); Send a Request To a Server use the open() and send() methods xhttp.open("GET", "ajax_info.txt", true); xhttp.send(); Method Description open(method, url, async) Specifies the type of request method: the type of request: GET or POST url: the server (file) location async: true (asynchronous) or false (synchronous) send() Sends the request to the server (used for GET) send(string) Sends the request to the server (used for POST)

onreadystatechange Property The readyState property holds the status of the XMLHttpRequest. The onreadystatechange property defines a function to be executed when the readyState changes. The status property and the statusText property holds the status of the XMLHttpRequest object. Property Description onreadystatechange Defines a function to be called when the readyState property changes readyState Holds the status of the XMLHttpRequest.  0: request not initialized  1: server connection established 2: request received  3: processing request  4: request finished and response is ready status 200: "OK" 403: "Forbidden" 404: "Page not found” statusText Returns the status-text (e.g. "OK" or "Not Found")

<html> <body> <h1>The XMLHttpRequest Object</h1> <button type="button" onclick="loadDoc()">Request data</button> <p id="demo"></p> <script> function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("POST", "demo_post.asp", true); xhttp.send(); </script> </body> </html>

<html> <style> table,th,td { border : 1px solid black; border-collapse: collapse; } th,td { padding: 5px; </style><body> <h1>The XMLHttpRequest Object</h1> <button type="button" onclick="loadDoc()">Get my CD collection</button> <table id="demo"></table> <script> function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); }; xhttp.open("GET", "cd_catalog.xml", true); xhttp.send();