title: Curl rest API to a second site in Javascript
body: <p>I am trying to display a result from a rest API GET request, for example, "<a href="http://ifconfig.co/ip/" rel="nofollow noreferrer">http://ifconfig.co/ip/</a>" on my page.  However, I am running into many different errors, and just cannot seem to get it down. 
  Her is what I have so far:</p>
  
  <pre><code>var req = new XMLHttpRequest();
  
  req.open('GET', 'https://ifconfig.co/ip', true);
  
  req.withCredentials = false;            
  
  req.setRequestHeader( 'Access-Control-Allow-Origin', '*' );
  
  
  req.send();
  
  document.write(req);
  document.write(req.responseText);
  document.write(req.responseXML);
  </code></pre>
  
  <p>In the javascript console it says "XMLHttpRequest cannot load <a href="https://ifconfig.co/ip" rel="nofollow noreferrer">https://ifconfig.co/ip</a>. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."</p>
  
  <p>I am very new to javascript, can anyone point me in the right direction?</p>
  
  <hr>