我正在使用.ajaxStart()和.ajaxStop()在发出ajax请求时显示模态.(开始和停止之间)
现在我想添加一个等待通知的longpoll函数,类似于本网站左上角的那个.
我现在的问题在于仅为longpolling请求禁用此模式.
注册"加载屏幕"打开和关闭处理程序:
$(document).ajaxStart(handleAjaxStart);
$(document).ajaxStop(handleAjaxStop);
Run Code Online (Sandbox Code Playgroud)
我的longpoll功能:
$.ajax({
timeout: 35000,
url: longPollUrl,
success: function(data){
if(data.queCount) $('#numQueCount').html(data.queCount);
if(data.queAccept) $('#numQueAccept').html(data.queAccept);
},
dataType: 'json',
complete: longpoll
});
Run Code Online (Sandbox Code Playgroud)
我试过了:
$().off('ajaxStart');
$().off('ajaxStop');
Run Code Online (Sandbox Code Playgroud)
..开始投票后重新连接处理程序,但没有快乐.
我也尝试将一个全局变量引入到handleAjaxStart()该函数的第一行返回,但这似乎完全杀死了加载屏幕.
任何想法如何实现这一目标?
也许没有区别,但要么比其他方式更好(或者可能是比两者更好的神秘'第三'方式!)......
var startTime;
$(document).ready(function() {
$("#lbl_ajaxInProgress").ajaxStart(function() {
// store the current date/time...
startTime = new Date();
// update labels
$(this).text('Yes');
$("#lbl_ajaxCallTime").text("-");
});
$("#lbl_ajaxInProgress").ajaxStop(function() {
// update labels
$(this).text('No');
$("#lbl_ajaxCallTime").text(myFunctionThatCalculatesTime(startTime));
});
});
Run Code Online (Sandbox Code Playgroud)
var startTime;
$(document).ready(function() {
$("#lbl_ajaxInProgress").ajaxStart(function() {
// update labels
$(this).text('Yes');
});
$("#lbl_ajaxInProgress").ajaxStop(function() {
// update labels
$(this).text('No');
});
$("#lbl_ajaxCallTime").ajaxStart(function() {
// store the current date/time...
startTime = new Date();
// update labels
$(this).text("-");
});
$("#lbl_ajaxCallTime").ajaxStop(function() {
// update labels
$(this).text(myFunctionThatCalculatesTime(startTime));
});
});
Run Code Online (Sandbox Code Playgroud)