ajax等待进度数,如果ajax少于X秒,如何延迟显示进度?
對(duì)于我能夠找到解決方案的好答案。
我最終想要本地化" loading"要基于元素ID顯示的圖像。全局ajaxStart()和ajaxComplete()功能不會(huì)處理本地事件。所以我用超時(shí)切換到beforeSend()函數(shù):
$('.item').click( function (e) {
e.preventDefault();
var theID = $(this).attr('data');
var theInfo = $('.holder#h' + theID);
var loader = $('.waiting#w' + theID);
$('.holder').slideUp(); //closes any open data holders
var ajaxLoadTimeout;
if (!$(theInfo).hasClass('opened')) {
$(this).addClass('clicked');
$(theInfo).addClass('opened');
$(theInfo).html(''); //removes any existing data
$.ajax({
url: '_core/inc/getdata.php',
type: 'POST',
data: ({dataid: theID}),
dataType: 'html',
//shows LOCAL loader before ajax is sent
//but waits 3 milliseconds before doing so
//most of the ajax calls take less than 3ms
//without the timeOut the loader "flashes" for a milisecond
beforeSend : function() {
ajaxLoadTimeout = setTimeout(function() {
$(loader).show();
}, 300);
},
success: function(data) {
$(theInfo).html(data);
//Hides LOCAL loader upon ajax success
clearTimeout(ajaxLoadTimeout);
$(loader).hide();
},
complete: function(){
$(theinfo).slideDown();
}
});
} else {
$(this).removeClass('clicked');
$(theInfo).removeClass('opened').slideUp();
}
});
相關(guān)的PHP / HTML:
echo '
'.$this_title.'
';
CSS:.waiting { discplay: none; }
我不知道這是對(duì)還是錯(cuò),但似乎在這里按預(yù)期工作。
如果該項(xiàng)目的加載時(shí)間超過(guò)幾毫秒,它允許字體真棒圖標(biāo)出現(xiàn)在項(xiàng)目標(biāo)題旁邊。
總結(jié)
以上是生活随笔為你收集整理的ajax等待进度数,如果ajax少于X秒,如何延迟显示进度?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: css3 3d旋转兼容模式下,前端CSS
- 下一篇: es文件浏览器自动上传ftp服务器,es