0

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);
Community
  • 1
  • 1
Jean
  • 21,665
  • 24
  • 69
  • 119
  • Try removing null and do req.send() instead – Shivam Shah Jan 27 '14 at 17:57
  • you cannot get pages/data from external sites unless the server supports cors or you use JSONP type ajax calls, or use some other language like php and curl to fetch the data and then return the page to the ajax call. Also note scraping a websites pages might be a violation of their tos – Patrick Evans Jan 27 '14 at 17:58

0 Answers0