Copy Code code as follows:
<script>
var xhr = ';
function Ajax ()
{
if (window. XMLHttpRequest)
{
var xhr = new xmlhttprequest;//Modern browser
}else
{
var xhr = new ActiveXObject (' microsoft.xmlhttp ');//ie
}
}
Ajax ()//1. Get Ajax objects
Xhr.onreadystatechange = function ()
{
if (xhr.readystate = = 4 && xhr.status = 200)
{
var data = Xhr.responsetext;//2. Judging status, receiving data (in string form), subsequent operations
}
}
Xhr.open (' Mode of request ', ' request address ', TRUE);//3. Asynchronous Transport connections
Xhr.send ([data]);//4. Send a request
Xhr.open (' Get ', ' demo.php?name=weichen&sex=0 ', TRUE);
Xhr.send ();
/*
Xhr.open (' POST ', ' demo.php ', TRUE);
Xhr.setresponseheader (' Content-type ', ' application/x-www-form-urlencoded ');
Xhr.send (' name=weichen&sex=0 ');
*/
member properties and member methods in the XHR object
Copy Code code as follows:
{
Member Properties:
HTTP status code for the status server response (for example, 200 or 404)
HTTP status code (OK or not found) returned as a string by the StatusText server response
ReadyState Browser requested status code (0 to 4)
Data results in string format for ResponseText server response
Data results in XML format for Responsexml server response
onReadyStateChange Ajax Request Events (event handlers that are invoked when readystate changes)
Mozilla's event handler function that is invoked when an error occurs during a onerror request
OnProgress event handler function called after content loading
Mozilla event handler called after the onload document has finished loading
Member Methods:
setRequestHeader (); Sets the header header information for the current request (adds a key/value pair for the message header to be sent to the server side)
Open (); Create a new request connection (initialize the Xhr object with Get, POST, URL, etc.)
Send (); Send a request (data that may need to be sent)
getResponseHeader ("server"); Returns the value of the specified HTTP header (such as server or last-modified)
Getallresponseheaser (); Returns a string of all HTTP headers separated by a newline character
Absort (); Terminate request
}