The XMLHttpRequest object is communicating with the server behind the scenes.When we create XMLHttpRequest object. then following methods and properties are available.
Methods
abort()
open()
SetRequestHeader
getAllResponseHeaders()
getResponseHeader()
Properties
Onreadystatechange
readyState
responseText
responseXML
abort()
This method cancels the current request.
open()
Opens a request to the server.
Syntax:open(method,url, async/ synch)
method : get,post.
url: url of the file
async : true , synch : false
setRequestHeader()
To set HTTP header when sent. This method is use for post only.
setRequestHeader(headername,headervalue)
For Example
Headername : Content-Type
Headevalue : text/xml
setRequestHeader("Content-Type", "text/xml");
send()
Sends the current request
getAllResponseHeaders()
This method return all HTTP headers as a String type variable.
getResponseHeader()
The methods returns the value of the HTTP headers specified in the method.
Properties of XMLHttpRequest Object.
Onreadystatechange
On readystatechange is a property of XMLHttpRequest object. we can also say event. And this Event is automatically trigger and each time this object change the value of readystate property (0,1,2,3,4).
0 means request not initialized
1 means server connection established
2 means request received
3 means processing request
4 means request finished and response is ready
when this value become 4 and status is 200 it means response is OK. This event send text to ResponseText property
ReadyState
Contains value that get by onreadystatechange.
ResponseText
Contains the response body as a String.
ResponseXML
Contains the response body as XML.