This is one of the first java script I have ever written and I shouldn't doing this in first place. The following code which is a ripoff of this question gives me the following output in Firebug. How do I start debugging this ? My intention is to fetch a webpage using JS and scrape it to get some useful information. Is there a better method to accomplish that ?
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<button type="button" onclick="RequestPage()">Request</button>
<script>
function RequestPage()
{
var req = new XMLHttpRequest();
req.open('GET', 'http://www.google.com', false);
req.send(null);
if(req.status == 200)
{
document.getElementById("demo").innerHTML = 'Success';
}
}
</script>
</body>
</html>
Firebug Output:
GET http://www.google.com/ 302 Found 34ms test.html (line 13)
NS_ERROR_FAILURE:
req.send(null);