JavaScript apparently waits for each AJAX call before sending another in a loop

Posted by itako on Stack Overflow See other posts from Stack Overflow or by itako
Published on 2010-06-16T10:36:05Z Indexed on 2010/06/16 10:52 UTC
Read the original article Hit count: 191

Filed under:
|
|
|
|

Hello. Straight to the point: I have this javascript:

for(item=1;item<5;item++)
{
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("GET",'zzz.php', true);
    xmlhttp.send();
}

And in PHP file something like this:

usleep(5);die('ok');

Now the problem is javascript seems to be waiting for each ajax call to be completed before sending another one. So the first response gets back after approx. 5 seconds, next after 10 seconds and so on.

That's a very simplified version of what I do, since the real script involves using cURL in PHP and jQuery as JS lib. But the problem remains the same.

Why do responses come back in 5 second intervals?

© Stack Overflow or respective owner

Related posts about php

Related posts about AJAX