pageLoad的事件触发由于IDLETIMEOUT插件多次? [英] PageLoad event fires multiple times due to idletimeout plugin?

查看:169
本文介绍了pageLoad的事件触发由于IDLETIMEOUT插件多次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在对一个asp.net web窗体项目的一些奇怪的问题,那里的页面加载和显示一些数据(基本上是一个gridview)。在页面加载事件中设置某个页面上的一个破发点时,我们发现了一些奇怪的。约1-2分钟后,我们的页面加载事件再次射击......和again..etc。我们不明白这是为什么发生的,但我们把范围缩小到JavaScript的code的一块,我们正在使用我们的网站主页上。

We are having some strange issues on an asp.net web form project where the page loads and displays some data (basically a gridview). We noticed something strange when setting a break point on a certain page in the page load event. After about 1-2 minutes our page load event was firing again...and again..etc. We couldn't understand why this was happening but we narrowed it down to one piece of javascript code that we are using on our site master page.

我们正在使用的 IDLETIMEOUT插件通过埃里克hynd。在code有一些JS,看起来像这样:

We are using the idletimeout plugin by eric hynd. The code has some js that looks like this:

// cache a reference to the countdown element so we don't have to query the DOM for it on each ping.
    var $countdown = $("#dialog-countdown");
    var sessionTimeoutWarning = '<%= ConfigurationManager.AppSettings["SessionWarningInSeconds"] %>';


    // start the idle timer plugin
    $.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
        idleAfter: sessionTimeoutWarning,
        serverResponseEquals: 'OK',
        onTimeout: function () {
            window.location = "/SessionExpired.aspx";
        },
        onIdle: function () {
            $(this).dialog("open");
        },
        onCountdown: function (counter) {
            $countdown.html(counter); // update the counter
        }
    });

如果我只是注释掉$ C $这一节c中的应用不再具有调用页面加载事件多次的问题。我们对我们的Site.Master这个code所以这基本上是发生在使用该网站主的页面。我们做了一些谷歌搜索,发现提及similiar问题的文章,但他们表示,这可以通过 IMG 标签造成的没有一个正确的的src 设置。但是,这不是我们的问题,我们的问题只是这个空闲超时插件导致网页加载事件触发多次,我们不知道为什么。一刻起,我发表意见code OUT一切工作正常。

If I simply comment out this section of the code the app no longer has issues calling the page load event multiple times. We have this code on our site.master so this happens basically to any page that uses the site master. We did some google searching and found articles that mention similiar issues but they stated this could be caused by img tags that do not have a correct src set. But this is not our issue, our issue is only that this idle timeout plugin is causing the page load event to fire multiple times and we are not sure why. The minute I comment the code out everything works as normal.

推荐答案

插件需要一个 keepAliveURL:参数要知道叫什么服务或处理程序维持会话。

The plug-in needs a keepAliveURL: parameter to know what service or handler to call to sustain the session.

如果您检查 GitHub的回购

If you check the GitHub Repo

$.ajax({
        timeout: options.AJAXTimeout,
        url: options.keepAliveURL,
        error: function(){
        self.failedRequests--;
     },
     success: function(response){
        if($.trim(response) !== options.serverResponseEquals){
             self.failedRequests--;
        }
     },
     complete: function(){
         if( recurse ){
             self._startTimer();
         }
     }
 });

您注意到应用依赖于Ajax调用需要

You notice the App depends on the ajax call needs

要解决:添加 keepAliveURL:监听器

$.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
    idleAfter: sessionTimeoutWarning,
    keepAliveURL: 'keepalive.asmx',
    serverResponseEquals: 'OK',
    onTimeout: function () {

监听器(任何Web方法都行)应内容(OK)回应您已经指示:

serverResponseEquals: 'OK',


[WebMethod]
public void keepalive()
{
    HttpContext.Current.Response.Write("OK"); 
    HttpContext.Current.Response.End();
}

这篇关于pageLoad的事件触发由于IDLETIMEOUT插件多次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆