title: Requests are pending on nodejs server after send using XMLHttpRequest
body: <p>I am sending request using front end code:</p>
  
  <pre><code>function sendDataToApi(json, callback) {
      var xhr = new XMLHttpRequest();
      xhr.open("POST", API_URL, true);
      xhr.setRequestHeader("Content-type", "application/json");
      xhr.onreadystatechange = function () {
          if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {
              callback(JSON.parse(xhr.responseText));
          }
      };
      xhr.send(json);
  }
  </code></pre>
  
  <p>On server side, there is a code:</p>
  
  <pre><code>var iterator = 0;
  app.post('/api', function (req, res) {
    loop = getRandomInt(10, 30); // generate random int in range 10-30
    //execute loop and wait after 1s for a X (var loop) second
    console.log("Task id: " + iterator + " started: " + loop + "ms");
    for (i = 0; i &lt; loop; i++) {
      console.log(" tick: " + i);
      wait(1000);
    }
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify({ response: iterator }));
  });
  </code></pre>
  
  <p>Wait:</p>
  
  <pre><code>//sleep for X ms
  function wait(ms) {
    var start = new Date().getTime();
    var end = start;
    while (end &lt; start + ms) {
      end = new Date().getTime();
    }
  }
  </code></pre>
  
  <p>I am using <code>var app = express();</code></p>
  
  <p>When I send one request, all is OK.</p>
  
  <p>When I send two or more request, second, third, and next request are in state pendign and they are executed after first request is finished.</p>
  
  <p>I dont know why, I am using <code>xhr.open("POST", API_URL, true);</code> thats mean true is asynchronous.</p>
  
  <p>I need execute my for loop (on server side) asynchronous.</p>
  
  <p>Thank you for any help.</p>
  
  <p>I want simulate some log function, which takes a lot of time...</p>
  
  <p>So, I need some loop, which takes some time, for example 30second server task function asynchronous to front end.</p>