[英]jQuery Ajax event binding
I am using the https://github.com/ehynds/jquery-idle-timeout to produce a Mint style idle timer which performs an Ajax call to a 'keep-alive' page. 我正在使用https://github.com/ehynds/jquery-idle-timeout生成Mint风格的空闲计时器,该计时器执行对“保持活动”页面的Ajax调用。
I also have a piece of Javascript for Ajax form submits that pops up a 'Please wait' message to alert the user that activity is occurring though the pages isn't loading. 我还为Ajax表单提交提供了一段Javascript,它会弹出“请稍候”消息,以提醒用户尽管页面没有加载,但活动正在发生。
For some reason the toggleAjaxLoader() function is getting bound to the ajax:before and ajax:complete events each time the keep alive page is polled. 由于某些原因,每次轮询保持活动页面时,toggleAjaxLoader()函数都将绑定到ajax:before和ajax:complete事件。 I do not want this as it is confusion to the user. 我不希望这样做,因为这会使用户感到困惑。 Why would this be binding to the idletimeout and/or how can I drill into what is happening? 为什么这会绑定到idletimeout和/或如何深入研究正在发生的事情?
Loading animation: 加载动画:
// Toggles our animated ajax loader image
function toggleAjaxLoader() {
jQuery('#ajax_loader').toggle();
}
Idle timeout: 空闲超时:
/*
* Inactivity notifier and auto logout
*/
jQuery(function(){
var redirectToURL = getAbsoluteUrl('/logout/auto=true'); // URL to relocate the user to once they have timed out
var keepAlive = getAbsoluteUrl('/keep-alive');
if (jQuery("#idletimeout").length) {
$.idleTimeout('#idletimeout', '#idletimeout a', {
idleAfter: 2700, // 45 minutes
warningLength: 60, // number of seconds to wait before redirecting the user
keepAliveURL: keepAlive,
AJAXTimeout: 2500,
pollingInterval: 5, // 60
expiredMessage: 'Your session has expired. You are being logged out for security reasons.', // message to show user when the countdown reaches 0
onTimeout: function(){
$(this).slideUp();
window.location.replace(redirectToURL);
},
onIdle: function(){
$(this).slideDown(); // show the warning bar
},
onCountdown: function( counter ){
$(this).find("span").html( counter ); // update the counter
},
onResume: function(){
$(this).slideUp(); // hide the warning bar
// Tums.bump_tums_session(session[:user].session['sessionGuid']);
}
});
};
});
I believe I found my answer, it is due to jQuery's global ajax event handlers , which by default the setting is set to true. 我相信我找到了答案,这是由于jQuery的全局ajax事件处理程序 ,默认情况下,该设置设置为true。 I set this to false it it appears to be working as expected. 我将其设置为false,它似乎按预期工作。
$.ajaxSetup({
global: false
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.