What Is Xmlhttprequest
What Is Xmlhttprequest
What Is Xmlhttprequest
The XMLHttpRequest object is the key to AJAX. It has been available ever since Internet Explorer
5.5 was released in July 2000, but was not fully discovered until AJAX and Web 2.0 in 2005 became
popular.
XMLHttpRequest XHR is an API that can be used by JavaScript, JScript, VBScript, and other web
browser scripting languages to transfer and manipulate XML data to and from a webserver using
HTTP, establishing an independent connection channel between a webpage's Client-Side and
Server-Side.
The data returned from XMLHttpRequest calls will often be provided by back-end databases.
Besides XML, XMLHttpRequest can be used to fetch data in other formats, e.g. JSON or even plain
text.
You already have seen a couple of examples on how to create an XMLHttpRequest object.
Listed below is listed are some of the methods and properties that you have to get familiar with.
XMLHttpRequest Methods
abort
getAllResponseHeaders
getResponseHeaderheaderName
openmethod, URL
The method parameter can have a value of "GET", "POST", or "HEAD". Other HTTP methods,
such as "PUT" and "DELETE" primarilyusedinRESTapplications may be possible.
The "async" parameter specifies whether the request should be handled asynchronously or
not. "true" means that the script processing carries on after the send method without waiting
for a response, and "false" means that the script waits for a response before continuing script
processing.
sendcontent
setRequestHeaderlabel, value
XMLHttpRequest Properties
onreadystatechange
The readyState property defines the current state of the XMLHttpRequest object.
The following table provides a list of the possible values for the readyState property:
State Description
readyState = 0 After you have created the XMLHttpRequest object, but before you have
called the open method.
readyState = 1 After you have called the open method, but before you have called send.
readyState = 3 After the browser has established a communication with the server, but
before the server has completed the response.
readyState = 4 After the request has been completed, and the response data has been
completely received from the server.
responseText
responseXML
Returns the response as XML. This property returns an XML document object, which can be
examined and parsed using the W3C DOM node tree methods and properties.
status
Returns the status as a number e. g. , 404for " NotFound " and200for " OK " .
statusText