weixin_33726313 2013-09-12 21:59 采纳率: 0%
浏览 44

jQuery Ajax事件绑定

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.

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.

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. 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?

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']);
            }
        });
    };
});
  • 写回答

1条回答 默认 最新

  • weixin_33695450 2013-09-12 22:18
    关注

    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. I set this to false it it appears to be working as expected.

    $.ajaxSetup({
       global: false
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog