title: Connecting JSON API for parsing
body: <p>I am looking to parse the following page and extract every instance of a name. <a href="http://api.openparliament.ca/politicians/" rel="nofollow noreferrer">http://api.openparliament.ca/politicians/</a>.</p>
  
  <p>I have been following this guide for reference: <a href="https://www.taniarascia.com/how-to-connect-to-an-api-with-javascript/" rel="nofollow noreferrer">https://www.taniarascia.com/how-to-connect-to-an-api-with-javascript/</a> However when it runs, there is nothing returned. What am I doing wrong?</p>
  
  <pre><code>var request = new XMLHttpRequest();
  
  request.open('GET', 'api.openparliament.ca/politicians/?format=json', true);
  request.onload = function () {
  
    // Begin accessing JSON data here
    var data = JSON.parse(this.response);
    if (request.status &gt;= 200 &amp;&amp; request.status &lt; 400) {
      data.forEach(politicians =&gt; {
        console.log(politicians.name);
      });
    } else {
      console.log('error');
    }
  }
  
  request.send();
  </code></pre>