Initial contactOnreadystatechangeI have read this article about the usage of the event handle.ArticleAfter the introduction, you will have a general understanding.
After a request is sent, the client cannot determine when the request will be completed. Therefore, an event mechanism is required to capture the Request status. The XMLHTTPRequest object providesOnreadystatechangeEvent. This is similar to the callback function.OnreadystatechangeAn event processing function can be specified to process the execution results of the XMLHTTPRequest object, for example:
Ajaxobj = Createajaxobject ();
VaR URL = " /Mytodoes/fetchtext? Id = " + ID;
Ajaxobj. Open ( " Get " , URL, True );
Ajaxobj. onreadystatechange = Changetabcallback;
Ajaxobj. Send ( Null );
After reading the W3C explanation, let's look at this example to better understand it.
OnreadystatechangeThe event is triggered when the readystate attribute changes. The value of readystate indicates the status of the current request.ProgramYou can perform different processing based on this value. Readystate can be set to 0: not initialized, 1: Loading, 2: Loading, 3: processing, and 4: processing. Once the value of the readystate attribute is changed to 4, you can access the response data returned by the server.
The value of readystate in an event is usually processed only after the request is completed, for example:
Function Changetabcallback (){
If (Ajaxobj. readystate = 4 ){
// Next Verification
}
}
Status stores the HTTP request response returned by the server.CodeIt indicates the request processing result. The meaning of common response code is as follows: Right.
In Ajax development, the most common response code is 200. The Code is as follows:
Function Changetabcallback (){
If (Ajaxobj. readystate = 4 ){
If (Ajaxobj. Status = 200 ){
// The server returns the correct data and starts Response Processing.
}
}
}
HTTP Status Code Description
200 successful request
202 requests accepted but not processed
400 Error request
404 The requested resource is not found
500 Internal Server Error
Source: http://www.okajax.com/a/200903/0315SJ2009.html