0

I am trying to configure a GET request to print whatever was returned from it, but there is no output. Here is the code:

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My First Paragraph</p>

<p id="demo"></p>

<script>

  function httpGet(theUrl)
  {
      var req = new XMLHttpRequest();
      req.responseType = 'json';
      req.open('GET', theUrl, true);
      req.onload  = function() {
       var jsonResponse = req.response;

      };
      req.send(null);
      return jsonResponse.toString();
  }

  document.getElementById("demo").innerHTML = httpGet(myURL);

</script>

</body>
</html>

PS. myURL is an API and when typed into the browser returns the correct data.

zarrexx
  • 27
  • 6

0 Answers0