并发发送ajax请求,流行的浏览器允许多少并发AJAX(XmlHttpRequest)请求?

Author: Luis Siquot

Purpose: Check ajax performance and errors

License: GPL

site5: Please don't drop json requests (nor delay)!!!!

*/

$r = (int)$_GET['r'];

$w = (int)$_GET['w'];

if($r) {

sleep($w);

echo json_encode($_GET);

die ();

} //else

?>

var _settimer;

var _timer;

var _waiting;

$(function(){

clearTable();

$('#boton').bind('click', donow);

})

function donow(){

var w;

var estim = 0;

_waiting = $('#total')[0].value * 1;

clearTable();

for(var r=1;r<=_waiting;r++){

w = Math.floor(Math.random()*6)+2;

estim += w;

dodebug({r:r, w:w});

$.ajax({url: '<?php echo $_SERVER['SCRIPT_NAME']; ?>',

data: {r:r, w:w},

dataType: 'json', // 'html',

type: 'GET',

success: function(CBdata, status) {

CBdebug(CBdata);

}

});

}

doStat(estim);

timer(estim+10);

}

function doStat(what){

$('#stat').replaceWith(

'

Request Time Sum='+what+

'

  /2='+Math.ceil(what/2)+

'

  /3='+Math.ceil(what/3)+

'

  /4='+Math.ceil(what/4)+

'

  /6='+Math.ceil(what/6)+

'

  /8='+Math.ceil(what/8)+

'

  (seconds)
'

);

}

function timer(what){

if(what) {_timer = 0; _settimer = what;}

if(_waiting==0) {

$('#showTimer')[0].innerHTML = 'completed in ' + _timer + ' seconds (aprox)';

return ;

}

if(_timer<_settimer>

$('#showTimer')[0].innerHTML = _timer;

setTimeout("timer()",1000);

_timer++;

return;

}

$('#showTimer')[0].innerHTML = 'don\'t wait any more!!!';

}

function CBdebug(what){

_waiting--;

$('#req'+what.r)[0].innerHTML = 'x';

}

function dodebug(what){

var tt = '

' + what.r + '' + what.w + ' '

$('#debug').append(tt);

}

function clearTable(){

$('#debug').replaceWith('

Request #Wait TimeDone
');

}

concurrent json requests

 

Elapsed Time: