Ajax request in for loop
<p>I'd like to loop 100 times ajax request with for loop. This is my code :</p>

<pre><code>for(var i=1; i&lt;100; i++)
{
  var num = i+1;

  var request = new XMLHttpRequest();
  request.open("GET", "http://localhost/test/1/2/main.php?t="+num+"", true);
  request.send(null);
  request.onreadystatechange = function() {

    if (request.readyState == 4) {

        var parser = new DOMParser();
        var doc = parser.parseFromString(request.responseText, "text/html");

        var rows = doc.getElementsByTagName("table")[0].getElementsByTagName("tbody")[0].getElementsByTagName("tr");

        var sum = 0;
        for(var j=0; j&lt;rows.length;j++)
        {
            sum += parseInt( rows[j].getElementsByTagName("td")[7].textContent.trim() );
        }
        alert(num);
    }


  }         
</code></pre>

<p>}</p>

<p>But it's not working. 
In console I see 100 times this information:</p>

<blockquote>
  <p>XHR finished loading: GET "<a href="http://localhost/test/1/2/main.php?t=2" rel="nofollow">http://localhost/test/1/2/main.php?t=2</a>".
  XHR finished loading: GET "<a href="http://localhost/test/1/2/main.php?t=3" rel="nofollow">http://localhost/test/1/2/main.php?t=3</a>".</p>
</blockquote>

<p>Etc. So everything should be ok. 
But I see alert only 14 times (I don't now why 14),no 100.</p>

<p>Why this program not working? </p>