title: Javascript HTTP request
body: <p>I have this function and when i run it in the console it gives me undefined:</p>
  
  <pre><code>function myRequest(url) {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", url);
      xhr.onreadystatechange = function () {
          if (xhr.readyState === 4 &amp;&amp; xhr.status === 200 &amp;&amp; xhr.contentType == "json") {
              console.log("Type", xhr.getResponseHeader("Content-Type"));
              console.log("Text", xhr.responseText);
          } else {
              console.log("This is not a Json file");
          }
      };
  
  
      xhr.send();
  }
  </code></pre>
  
  <p>The url I'm trying to get the data from is this : <a href="https://hotell.difi.no/api/json/bergen/dokart" rel="nofollow noreferrer">https://hotell.difi.no/api/json/bergen/dokart</a>?</p>
  
  <p>I really need some help figuring out why this is not working, thank you very much. </p>