0
<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

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.