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 provides the onreadystatechange event to implement this function. This is similar to the callback function.
The onreadystatechange event specifies an event processing function 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 );
Onreadystatechange
The 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 changes
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 ){
// Perform the next Verification
}
}
Status stores the HTTP request response returned by the server. Code indicates the request processing result, the meaning of common response codes 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, start Response Processing
}< BR >}< br> HTTP status code meaning
200 successful request
202 request accepted but not completed
400 Error request
404 request resource not found
500 internal server error