我想在提出ajax请求时添加一个进度条,进度条值由setTimeout更改。但是当我继续发送请求时,值会变得越来越快。下面是我的代码,有谁知道如何清除在 ajaxStart 部分设置的 ajaxStop 超时?如何清理所有超时?
var $reportContent = $("#reportDataDiasplay");
var timeOut;
$(document).ajaxStart(function(){
if($(".ui-dialog").length==0){
$reportContent.append("<div id='progressBarDialog'><div id='progressbar'></div></div>");
var $progressbarDialog = $("#progressBarDialog");
$progressbarDialog.dialog({
modal: true,
width:175,
height:50,
closeOnEscape: false,
autoOpen: false
});
$(".ui-dialog-titlebar").hide();
}
var $progressbar = $( "#progressBarDialog #progressbar" );
$progressbar.progressbar({value:false});
$progressbar.progressbar( "value",0 );
function progress() {
clearTimeout(timeOut);
var val = $progressbar.progressbar( "value" ) || 0;
if ( val < 75 ) {
$progressbar.progressbar( "value", val + Math.random() * 25 );
}
if(val < 99){
timeOut = setTimeout( progress, 300 );
}
}
timeOut = setTimeout( progress, 300 );
$("#progressBarDialog").dialog("open");
});
$(document).ajaxStop(function(){
$("#progressBarDialog").dialog('close');
});