Last Updated on December 1, 2015
The readyState of a document can be one of following:
Ripped from developer.mozilla.org
loading
The document is still loading. TCP handshake is in progress.
interactive
The document has finished loading and the document has been parsed but sub-resources such as images, stylesheets and frames are still loading. The state indicates that the DOMContentLoaded event has been fired.
complete
The document and all sub-resources have finished loading. The state indicates that the load event has been fired. When the value of this property changes a readystatechange event fires on the document object.
Stack overflow on the readystate numbers
function Request(url, callback){
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else{
return false;
}
var readyStateChange = function(){
console.log(httpRequest.readyState);
if (httpRequest.readyState == 4) {
callback(httpRequest.responseText);
}
};
if (isFirefox && firefoxVersion > 3) {
httpRequest.onload = readyStateChange;
} else {
httpRequest.onreadystatechange = readyStateChange;
}
console.log(httpRequest, url);
httpRequest.open('GET', url, true);
httpRequest.send(null);
}