The methods and attributes of the XMLHttpRequest object are listed below, marked in red as the most likely
Related methods:
Abort () stops the current request
GetAllResponseHeaders () returns all HTTP Request Response Headers as key/value pairs.
GetResponseHeader ("header") returns the string value of the specified header.
Open ("method", "url") creates a call to the server.
Send (content) sends a request to the server
SetRequestHeader ("header", "value") sets the specified header to the provided value. You must call open () before setting any header ()
Related attributes:
This event processor is triggered when the onreadystatechange status changes. Generally, a JavaScript function is called.
ReadyState Request status 0 = not initialized, 1 = loading, 2 = loaded, 3 = interaction, 4 = completed
ResponseText server response, which is a string
The response of the responseXML server, expressed as XML. This object can be parsed as a DOM object.
Status Server HTTP status code (200 corresponds to OK, 404 corresponds to Not Found (Not Found ),
Corresponding text of statusText HTTP status code (OK or Not Found (Not Found)
A standard XMLHttpRequest object to implement ajax
<Script type = "text/javascript">
Var xmlHttp;
// Function 1: Create an XMLHttpRequest object
Function createXMLHttpRequest (){
// Different IE versions
If (window. ActiveXObject ){
Try {xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");}
Catch (e) {xmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");}
}
// Non-IE
Else if (window. XMLHttpRequest ){
XmlHttp = new XMLHttpRequest ();
}
}
// Function 2: The function to be called
Function startRequest (){
CreateXMLHttpRequest ();
Var url = "XXX. ashx? "+ New Date (). getTime ();
XmlHttp. onreadystatechange = handleStateChange;
XmlHttp. open ("GET", url, true );
XmlHttp. send (null );
}
// Function 3: The Event function triggered when the status changes
Function handleStateChange (){
If (xmlHttp. readyState = 4 ){
If (xmlHttp. status = 200 ){
Var result = xmlHttp. responseText;
Document. getElementById ("validateMessage"). innerText = result;
}
}
}
</Script>