HTML and CSS Reference
In-Depth Information
EXAMPLE (S AMPLE C ODE )
objectRequest.open(“GET”, “http://localhost/test.php?name=George”, true);
objectRequest.send(null);
EXAMPLE (S AMPLE C ODE )
objectRequest.open(“POST”, “http://localhost/hello.php”);
objectRequest.setRequestHeader(“Content-Type”,
“application/x-www-form-urlencoded”);
objectRequest.send(“first=Joe&last=Blow”);
18.3.4 Step 3: Monitoring the State of the Server Response
Monitoring the State of the Server. After sending a request to the server, we need
to know when the request has completed and what to do with the information when it
comes back. The onreadystatechange event handler of the XMLHttpRequest object is
assigned a function that will be called automatically when the onreadystatechange event
handler is triggered; that is, when the state of the server changes.
EXAMPLE (S AMPLE C ODE )
ajaxRequest.onreadystatechange = function(){
// The function will defined later
}
What does readyState mean? The XMLHttpRequest object keeps track of the status of
the server's response in another property called readyState . This property has one of the
values shown in Table 18.3.
Table 18.3 The readyState property of the XMLHttpRequest Object
Status
Value
0
Object, has been created, not initialized
1
Loading, send method not yet called
2
Loaded, send method called, headers not available
3
Interactive, some data has been received, status and response headers not
available
4
Complete, all data has been received and is available
 
 
Search WWH ::




Custom Search