将ajax请求设为零

时间:2012-08-04 12:40:45

标签: javascript ajax

我正在使用简单的ajax请求。当我调用以下函数时

function onsub()
    {
        alert(document.getElementById('source').value);
        var http=new XMLHttpRequest();
        var name="rohit";
        if(http.open("POST", "sub.php?field="+name, true)) 
        {
        alert('yes');
        }


        http.onreadystatechange = function() 
        {
        alert(http.status);
            if(http.readyState == 4 && http.status == 200) 
            {

                alert('i m back');
            }
            else
            {
                alert('sorry');

            }
        }  

        http.send();
    }

    </script>

当我要求http.readyState的值时,我的答案为4,但状态为0。为什么这个价值会来?

0 个答案:

没有答案