var xhr;
XHR = new XMLHttpRequest (); Create an Asynchronous object
Xhr.open ("Get", "Test.ashx", true); The three parameters in the get way brackets are: 1. How to send a request 2. Page 3 of the sample request. Whether asynchronous
Xhr.open ("Post", "Test.ashx", true);
Xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); Post mode to send data
This callback function is primarily used to detect whether the server is returning data to an asynchronous object
Xhr.setrequestheader ("If-modified-since", "0"); Set the browser not to use the cache
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
The ReadyState property indicates several states in which the XMLHttpRequest object is in the process of sending/receiving data. The XMLHttpRequest object undergoes 5 different states.
0: not initialized. Object has been created, but not initialized yet, the open method has not been called;
1: Open. The object has been created and initialized, but the Send method has not been called;
2: Sent. The Send method has been called, but the object is waiting for the status code and header to return;
3: Receiving. Some of the data has been received, but the properties and methods of the object cannot be used, because the state and response headers are incomplete;
4: Loaded. All data received
if (xhr.status==200) {//The status code of the response message returned by the detection server is 200
alert (Xhr.responsetext); Response data returned by the server
Parsing the data returned by the server in Jason format
var S=xhr.responsetext;
var json=eval ("(" +s+ ")");
alert (jason.data);
}
};
};
Xhr.send (NULL); Asynchronous object Send Request
Xhr.send ("txtname=by&txtpwd=0703"); Send data as Post
The process of implementing asynchronous requests by Ajax