The XMLHttpRequest.readyState
property is what you're looking for.
From the Spec you've given, you will see that all those "boolean" flags are actually numeric values.
- UNSENT (numeric 0)
- OPENED (numeric 1)
- HEADERS_RECEIVED (numeric 2)
- LOADING (numeric 3)
- DONE (numeric 4)
These values are the result of XMLHttpRequest.onreadystatechange
event handler.
Basically, in order to get those values, do something of this effect.
//In Javascript
var request = new XMLHttpRequest();
if (request) {
request.onreadystatechange = function() {
if (request.readyState == 4) { //Numeric 4 means DONE
}
};
request.open("GET", URL + variables, true); //(true means asynchronous call, false otherwise)
request.send(""); //The function that executes sends your request to server using the XMLHttpRequest.
}
Bear in mind, always write the onreadystatechange
event BEFORE calling the XMLHttpRequest.send()
method (if you decide to do asynchronous calls). Also, asynchronous calls will call XMLHttpRequest.onreadystatechange
event listener so it's always vital you have that implemented.
More info on Wikipedia