Multiple Ajax Request from the same page at the same time

422 views
Skip to first unread message

aerox

unread,
Nov 9, 2009, 11:05:15 PM11/9/09
to Prototype & script.aculo.us
hi all,
i'm using prototype to perform 3 ajax request at the same time in the
same page.

the probeleme is i have the impression that my requests are not
asynchronous :

i call first a page named foo.php => do a sleep(40)
and second a page named bar.php => echo "toto";

my javascript code:

function test1(){
var MyAjax = new Ajax.Request(/foo.php,{
method: 'get',
asynchronous:true,
encoding: 'UTF-8',
onSuccess: function(){
return;
},
onFailure: function(){
return;
});
}

function test2(){
var MyAjax = new Ajax.Request(/bar.php,{
method: 'get',
asynchronous:true,
encoding: 'UTF-8',
onSuccess: function(){
return;
},
onFailure: function(){
return;
});
}

<a href="#" onclick="test1();test2();return false;">Start Test</a>

i can see with firebug that the both request take 40s to be executed.
or when i execute only test2(); it take 20ms.

it's like the second request wait for the first to finish executing
together ??!!

any ideas ?

T.J. Crowder

unread,
Nov 10, 2009, 6:50:42 AM11/10/09
to Prototype & script.aculo.us
Hi,

Most browsers, and most servers, limit the number of simultaneous
requests between the same two endpoints. Usually that limit is two
requests at a time, although I've also seen it be just one. Some
browsers let the user configure it.

You can count on one (obvious -- well, to the extent you can count on
networks at all); more than that and all bets are off. This isn't at
the Prototype level, it's at the browser and server HTTP
implementation level.

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com
Reply all
Reply to author
Forward
0 new messages