Reputation: 1708
I am trying to open the page in my tag. I have used following code.
Javascript:
function tempFunction() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
document.getElementById("page").innerHTML = xhr.response;
}
};
xhr.open("GET", "http://stackoverflow.com/", false);
xhr.send();
}
HTML:
<input type="button" id="btn" name="btn" value="Load" onclick="tempFunction()" />
<div id="page"></div>
Reference link: http://jsfiddle.net/DZmBG/3/
But when I tried by changing the URL to stackoverflow my code throw error:
Unhandled exception at line 49, column 13 in http://localhost:10642/WebForm2.aspx
0x800a139e - JavaScript runtime error: NetworkError
Is there any thing wrong am I doing?
Can any one help me to solve this?
Thank you in advance...!
Upvotes: 0
Views: 3005
Reputation: 15
(would comment but I don't have enough rep)
I get exatly the same error message (0x800a139e - JavaScript runtime error: NetworkError) while trying to access a local file without permission.
So I would suspect you are trying a cross-domain call which is allowed in codeacademy.com but not on stackoverflow.com, and thus it is failing.
If that's not the case someone please correct me
Upvotes: 1
Reputation: 21
The reason for the error is No 'Access-Control-Allow-Origin' header is present on the requested resource.The stack overflow may not allowing a direct http hit to their server.for more help regarding this issue please see the following post (it solves one of the similar issue),Hope it will help
Origin is not allowed by Access-Control-Allow-Origin
Upvotes: 0