簡體   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