I have the following code that works fine in IE:
<HTML>
<BODY>
<script language="JavaScript">
text="";
req = new XMLHttpRequest();
if (req)
{
req.onreadystatechange = processStateChange;
req.open("GET", "http://www.boltbait.com", true);
req.send();
}
function processStateChange()
{
// is the data ready for use?
if (req.readyState == 4) {
// process my data
alert(req.status);
alert(req.responseText);
}
}
</script>
</BODY>
</HTML>
In IE, the first alert returns 200, the second returns the web page.
However, in Chrome the first alert returns 0 and the second returns the empty string.
My intent is to grab a web page into a string for processing. If I’m not doing this right, how should I be doing this?
Thanks.
In general, due to the same origin policy (for security reasons), you can’t make request to URLs outside your domain. So, if your domain isn’t
boltbait.com, you can’t make that request. What’s strange is that IE doesn’t give you an error…However, in Chrome, an extension can make cross-origin requests (check this).