<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.
asked Jul 14, 2010 at 13:40
ParoX
5,96925 gold badges87 silver badges156 bronze badges
1 Answer 1
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.
answered Jul 14, 2010 at 13:44
Chris Diver
19.9k4 gold badges50 silver badges58 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Andir
That's what it is. Here is an example that returns a 404 with your code: jsfiddle.net/dFyjt
default