1

I'm trying to follow this answer but I'm having troubles: HTTP GET request in JavaScript?

I have a file called index.html with the following code in it:

<!DOCTYPE html>
<html>
<body>
<script>


function httpGetAsync(theUrl, callback)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() { 
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            callback(xmlHttp.responseText);
    }
    xmlHttp.open("GET", theUrl, true); // true for asynchronous 
    xmlHttp.send(null);
}

function call(response){
   // does nothing
}

httpGetAsync("https://www.google.ca/",call);

</script>
</body>
</html>

the majority of this code is directly from the answer to the question I linked above however I am getting this error in the console:

Failed to load https://www.google.ca/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Any help is appreciated, thanks

Mathew
  • 1,116
  • 5
  • 27
  • 59

0 Answers0