title: "XMLHttpRequest Exception 101" on nested AJAX queries
body: <p>I'm doing an AJAX fetch of a binary file the I am parsing in javascript. (Quake 2 BSPs, if anyone cares.) The code to fetch and parse the initial file is working fine, and looks roughly like this:</p>
  
  <pre><code>function loadFile(url) {
      var request = new XMLHttpRequest();
  
      request.onreadystatechange = function () {
          if (request.readyState == 4 &amp;&amp; request.status == 200) {
              var parsed = parseFile(request.responseText);
          }
      };
  
      request.open('GET', url, true);
      request.overrideMimeType('text/plain; charset=x-user-defined');
      request.setRequestHeader('Content-Type', 'text/plain');
      request.send(null);
  }
  </code></pre>
  
  <p>As I said, that works fine, and everything loads and parses correctly. However, the file also describes several secondary files (textures) that need to be retrieved as well, and so I've added an inner loop that should load and parse all of those files, like so:</p>
  
  <pre><code>function loadFile(url) {
      var request = new XMLHttpRequest();
  
      request.onreadystatechange = function () {
          if (request.readyState == 4 &amp;&amp; request.status == 200) {
              var parsed = parseFile(request.responseText);
              for(var i = 0; i &lt; parsed.files.length; ++i) {
                  loadSecondaryFile(parsed.files[i].url); // Request code here is identical to this function
              }
          }
      };
  
      request.open('GET', url, true);
      request.overrideMimeType('text/plain; charset=x-user-defined');
      request.setRequestHeader('Content-Type', 'text/plain');
      request.send(null);
  }
  
  function loadSecondaryFile(url) {
      var request = new XMLHttpRequest();
  
      request.onreadystatechange = function () {
          if (request.readyState == 4 &amp;&amp; request.status == 200) {
              var parsed = parseSecondaryFile(request.responseText);
          }
      };
  
      request.open('GET', url, true);
      request.overrideMimeType('text/plain; charset=x-user-defined');
      request.setRequestHeader('Content-Type', 'text/plain');
      request.send(null);
  }
  </code></pre>
  
  <p>But every request made from within that loop immediately fails with the message (in Chrome, Dev Channel): <b>NETWORK_ERR: XMLHttpRequest Exception 101</b> This strikes me as strange, since if I call <code>loadSecondaryFile</code> outside of <code>loadFile</code> it works perfectly.</p>
  
  <p>My initial impression was that initiating an one ajax call in the <code>onreadystatechage</code> of another may be bad juju, but wrapping the secondary ajax calls in a <code>setTimer</code> doesn't make any difference.</p>
  
  <p>Any ideas?</p>