title: Web Workers and JSON
body: <p>I am sure there is something that I am missing from this code, I just can not figure out what it is. </p>
  
  <p>Here is the main page:</p>
  
  <pre><code>  &lt;script&gt;
      function wwCallback(e) {
          document.write(e.data);
      }
      function wwError(e) {
          alert(e.data)
      }
      $(document).ready(function () {
          var worker = new Worker("sync.js");
          worker.onmessage = wwCallback;
          worker.onerror = wwError;
          worker.postMessage({
              'cmd': 'downloadUser',
              'url': 'server.php'
          });
          console.log("WW Started");
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Server.php simply echoes a JSON string and I have verified that it is both valid and working using normal ajax requests. </p>
  
  <p>Here is my web workers code:</p>
  
  <pre><code>function getData(url) {
  var req = new XMLHttpRequest();
  
  //expect json
      req.open('GET', url);
      req.send(null);
      req.onreadystatechange = function () {
          if (req.readyState == 4) {
              if (req.status == 200) {
                  self.postMessage(req.responseText);
              }
          }
      }
  } 
  
  self.addEventListener('message', function (e) {
    var data = e.data;
    switch (data.cmd) {
      case 'downloadUser':
          getData(data.url);
     }
      self.close();
  }, false);
  </code></pre>
  
  <p>Could anyone point me in the right direction?</p>