XMLHttpRequest is used to exchange data with the server in the background. This means that you can update a part of a webpage without reloading the entire webpage.
Create an XMLHTTPRequest object:
VaR XMLHTTP;
If (window. XMLHttpRequest)
{// Code for IE7 +, Firefox, chrome, opera, Safari
XMLHTTP = new XMLHttpRequest ();
}
Else
{// Code for IE6, ie5
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Ajax-send a request to the server:
To send requests to the server, we use the open () and send () Methods of the XMLHTTPRequest object, refer to: http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_send.asp
xmlhttp.open("GET","test1.txt",true); xmlhttp.send();
Ajax-server response:
To obtain a response from the server, use the responsetext or responsexml attribute of the XMLHTTPRequest object. For details, refer:
Http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_response.asp
Attribute |
Description |
Responsetext |
Obtain response data in string format. |
Responsexml |
Obtain response data in XML format. |
Ajax-onreadystatechange event
Reference: http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_onreadystatechange.asp