并发发送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:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值