XMLHttpRequest.status always returning 0
        Posted  
        
            by Michael
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Michael
        
        
        
        Published on 2010-05-02T06:31:39Z
        Indexed on 
            2010/05/02
            6:37 UTC
        
        
        Read the original article
        Hit count: 192
        
html
<a href="#" onclick="MyObj.startup()">click me</a>
js code
var MyObj = 
{
    startup : function()
    {
        var ajax = null;
        ajax = new XMLHttpRequest();
        ajax.open('GET', 'http://www.nasa.gov', true);
        ajax.onreadystatechange = function(evt)
        {
            if(ajax.readyState == 4)
            {
                if (ajax.status == 200)
                {
                    window.dump(":)\n");
                }
                else
                {
                    window.dump(":(\n");
                }
            }
        }
        ajax.send(null);
    }
}
ajax.status always returning 0, no matter which site it is, no matter what is the actual return code. I say actual, because ajax.statusText returning correct value, eg OK or Redirecting...
ajax.readyState also returns proper values and 4 at the end.
© Stack Overflow or respective owner