繁体   English   中英

jQuery Ajax事件绑定

[英]jQuery Ajax event binding

我正在使用https://github.com/ehynds/jquery-idle-timeout生成Mint风格的空闲计时器,该计时器执行对“保持活动”页面的Ajax调用。

我还为Ajax表单提交提供了一段Javascript,它会弹出“请稍候”消息,以提醒用户尽管页面没有加载,但活动正在发生。

由于某些原因,每次轮询保持活动页面时,toggleAjaxLoader()函数都将绑定到ajax:before和ajax:complete事件。 我不希望这样做,因为这会使用户感到困惑。 为什么这会绑定到idletimeout和/或如何深入研究正在发生的事情?

加载动画:

// Toggles our animated ajax loader image
function toggleAjaxLoader() {
  jQuery('#ajax_loader').toggle();
}

空闲超时:

/*
 * 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']);
            }
        });
    };
});

我相信我找到了答案,这是由于jQuery的全局ajax事件处理程序 ,默认情况下,该设置设置为true。 我将其设置为false,它似乎按预期工作。

$.ajaxSetup({
   global: false
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM