The client uses XMLHTTP to send a request to obtain the server response data, and uses JavaScript to operate the Dom to update the page. This is also called the brushless newest Update page) the submission method updates the web page trend.
XMLHTTP relies on XMLHttpRequest to complete the response from the client to the server. XMLHttpRequest provides two methods: open and send. The open method is used to initialize XMLHttpRequest.
Object, request method (get, post, etc.), secure connection, etc. after calling the open method, you must call the send method to send the HTTP request (HTTP request) to return HTTP reponse (HTTP response ).
Refer to the introduction to the send method in msdn:
This method is synchronous or asynchronous, depending on the value of the basync parameter in the open call. if open is called with basync = false, this call does not return until the entire response is already ed or the Protocol Stack times out. if open is called with basync = true, this call returns immediately.
Whether the send method is synchronous or asynchronous depends on the basync parameter in the open method. If basync = false, the send method works in the synchronous state. After an HTTP request is sent, only when the client receives all the response data from the server or the Protocol Stack times out! Otherwise, basync = true, which works asynchronously and returns directly.
In practice, set basync = true to make XMLHttpRequest work in asynchronous state after the send method is called. If it is set to synchronous state, it may lead to unnecessary long wait!
In addition, no matter how synchronous or asynchronous requests work, how does XMLHttpRequest obtain the response data returned by the server?
See the following sample code:
Program code <SCRIPT>
VaR XMLHTTP = NULL;
Function postorder (xmldoc)
{
Varxmlhttp = new activexobject ("msxml2.xmlhttp ");
XMLHTTP. Open ("Post", "http: // myserver/orders/processorder. asp", false );
XMLHTTP. onreadystatechange = handlestatechange;
XMLHTTP. Send (xmldoc );
}
Function handlestatechange ()
{
If (XMLHTTP. readystate = 4)
{
Alert ("result =" + XMLHTTP. responsexml. XML );
}
}
</SCRIPT>
The server returns the response data and is fully loaded. You can use the XMLHttpRequest attribute readstate to know that the value has changed to 4-completed (loaded ),
When the readstate changes, the onreadstatechange callback function in the XMLHTTPRequest object is called. In the function, the XMLHTTP. readystate = 4 is verified,
The XML document is obtained here (if the server returns XML document data ).