title: XMLHttpRequest and Web Workers Access-Control-Origin
body: <p>I'm dealing with some Access-Control-Origin issues when using webworkers to make an XMLHttpRequest.</p>
  
  <p>The issue is easily reproducible in this code, main.js:</p>
  
  <pre><code>var worker = new Worker('js/createSimplePage.js');
  worker.onmessage = function () {
    console.log('message recieved');
  };
  </code></pre>
  
  <p>And js/createSimplePage.js:</p>
  
  <pre><code>var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState === 4 &amp;&amp; xmlhttp.status === 200) {
      console.log(xmlhttp.responseText);
    }
  };
  xmlhttp.open("GET", "http://search.twitter.com/search.json?q=balling&amp;rpp=20&amp;callback=", true);
  xmlhttp.setRequestHeader('Content-Type', 'text/plain');
  xmlhttp.send();
  </code></pre>
  
  <p>If I include createSimplePage.js in the header of index.html, it runs fine and prints the correct response from the twitter API. However, if I only load main.js and let it try to load createSimplePage.js as a web worker then I receive the error:</p>
  
  <pre><code>XMLHttpRequest cannot load http://search.twitter.com/search.json?q=balling&amp;rpp=20&amp;callback=. 
  Origin file:// is not allowed by Access-Control-Allow-Origin.
  </code></pre>
  
  <p>A similar error occurs when hosting the files on SimpleHTTPServer except the error is then   </p>
  
  <pre><code> "Origin http://127.0.0.1:8000 is not allowed by Access-Countrol-Allow-Origin."
  </code></pre>
  
  <p>I don't understand why loading it as a web-worker would break it so it can't access the API.</p>