开发者

XMLHttpRequest simple HTTP GET not working?

<html>
<body>
<SCRIPT type="text/javascript">
 var xmlHttp = new XMLHttpRequest();
    var async = true;

    xmlHttp.open("GET", "http://www.google.com", async);
    if(async) 
    {
        xmlHttp.onreadystatechange = function() 
        {
            if(xmlHttp.readyState == 4)
            {
                if (xmlHt开发者_高级运维tp.status==200) alert("It works!")
                else if (xmlHttp.status==0) alert("Arggggg!")
                else alert("Status is "+xmlHttp.status)
            }
        }
    }
    xmlHttp.send();
</script>

</body>
</html>

I am just curious of XMLHttpRequest to see it up and working, but I can't get status to be non-zero. The examples seem so easy, yet it's not working. I've tried about 4 examples. What the heck ?

All I want to do is read a webpage and see the HTML in plain text.


I think this is your problem.

http://en.wikipedia.org/wiki/Same_origin_policy

Simply put, you cannot access google through an XMLHttpRequest because the page/JS isn't served from Google.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜