views:

34

answers:

1
<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 (xmlHttp.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.

+2  A: 

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.

Chris Diver
That's what it is. Here is an example that returns a 404 with your code: http://jsfiddle.net/dFyjt/
Andir