title: How to fix an XMLHttpRequest.open() returning code 0 when the contents are apparently correct?
body: <p>I am attempting to make a call to an API using the link that has been automatically generated by the developers. I am using the XMLHttpRequest.open() method based on the tutorial at <a href="https://javascript.info/xmlhttprequest" rel="nofollow noreferrer">https://javascript.info/xmlhttprequest</a>. However, when I try to make a call, the only status I am able to achieve is "0", which I think means something on my end(?).</p>
  
  <p>I have tried different links to other APIs, including ones that don't require anything besides the plain link, and have gotten the same response, which means that it's not necessarily something to do with the API I want, and other solutions (such as $.JSON().done()) aren't cooperating either.</p>
  
  <p>My very minimal code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;button onclick="getEndDate()"&gt;Click Me&lt;/button&gt;
  
  &lt;script&gt;
    function getEndDate() {
    alert("in function");
    // create request
    var request = new XMLHttpRequest()
    alert("request made");
    // request data from API (API link automatically generated)
  request.open('GET', 'https://holidayapi.com/v1/holidays?key=validkey&amp;country=US&amp;year=2018&amp;pretty', true)
    alert("request opened"+ request.status);
    // send request (?)
    request.send()
    alert("request sent");
  request.onload = function() {
    alert("request loaded");
    var data = JSON.parse(this.response)
    // If we receive a valid code
    if (request.status &gt;= 200 &amp;&amp; request.status &lt; 400) {
      data.forEach(holiday =&gt; {
        alert(holiday.name, holiday.date);
      })
    } else {
      alert('error');
    }
    }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I expect to be able to run through all of the alerts at the very least, however I can only get to "request sent", meaning there is a problem with loading the result of the request. In the status, as mentioned before, I would be expecting a 200 instead of 0.</p>
  
  <p>Am I approaching this entirely the wrong way? If so, what way should I be trying to call the API?</p>