I have a snippet of Javascript that I need to debug:
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE) {
if (this.status === 200) {
success = true;
}
}
};
Stepping through on Chrome and Firefox, I have found that the first "if" is failing. I can see that this.readyState
is set to 1
, which judging by the W3C spec should mean OPENED
. However XMLHttpRequest.DONE
shows as undefined
rather than 4
in Firebug.
http://www.w3.org/TR/XMLHttpRequest/#states
Is there a problem in Firefox and Chrome whereby these values are not supported?
readyState is both 2 (when the headers are received) and 4 (when the response has been downloaded) when any status code is returned.
Some browser does not know XMLHttpRequest.DONE
property, so you should check it as follows before first 'if':
var DONE = (typeof XMLHttpRequest.DONE !== 'undefined') ? XMLHttpRequest.DONE : 4;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With