Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with XMLHttpRequest.DONE values supported in FF / Chrome

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?

like image 746
MeanwhileInHell Avatar asked Aug 01 '11 12:08

MeanwhileInHell


People also ask

What is the meaning of readyState 2 in XMLHttpRequest?

readyState is both 2 (when the headers are received) and 4 (when the response has been downloaded) when any status code is returned.


1 Answers

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;
like image 51
stoshiya Avatar answered Sep 21 '22 16:09

stoshiya