gpt4 book ai didi

javascript - JQuery idleTimeout 功能中的 "pollingInterval:"问题

转载 作者:行者123 更新时间:2023-11-29 22:08:48 27 4
gpt4 key购买 nike

我在这里使用 JQuery idleTimeout 插件:

http://www.erichynds.com/examples/jquery-idle-timeout/example-mint.htm

当我在我的代码中实现时它工作正常,但每当我启动我的页面时它每次刷新 5 次所以我通过删除 idleTimeout 代码进行检查。然后它没有给出这个问题。

在详细了解之后,我发现如果我删除或注释“pollingInterval:2”这行代码,一切正常,刷新问题解决并且 TimeOut 功能仍然有效。

谁能帮我理解 pollingInterval:2 实际上在做什么。

这是插件的代码

JS:

 <script type="text/javascript">
// setup the dialog
$("#dialog").dialog({
autoOpen: false,
modal: true,
width: 400,
height: 210,
closeOnEscape: false,
draggable: false,
resizable: false,
buttons: {
'Yes, Keep Working': function () {
$(this).dialog('close');
},
'No, Logoff': function () {
// fire whatever the configured onTimeout callback is.
// using .call(this) keeps the default behavior of "this" being the warning
// element (the dialog in this case) inside the callback.
$.idleTimeout.options.onTimeout.call(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");

// start the idle timer plugin
$.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
idleAfter: 600,
pollingInterval: 2, //<--- THIS IS CAUSING ISSUE
serverResponseEquals: 'OK',
onTimeout: function () {
window.location = "/Home/Index/";
},
onIdle: function () {
$(this).dialog("open");
},
onCountdown: function (counter) {
$countdown.html(counter); // update the counter
}
});

</script>

它生成的对话框,

<!-- Session Time Out Message box -->
<div id="dialog" title="Your session is about to expire!">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 50px 0;"></span>You will be logged off in <span id="dialog-countdown" style="font-weight: bold"></span>seconds. </p>
<p>Do you want to continue your session?</p>
</div>

这里是需要添加的2个Jquery:

http://www.erichynds.com/examples/jquery-idle-timeout/src/jquery.idletimer.js
http://www.erichynds.com/examples/jquery-idle-timeout/src/jquery.idletimeout.js

如果您需要任何其他信息,请告诉我!

请提出建议!

最佳答案

我能够找到问题的解决方案,所以想分享它:

问题是我遗漏了一行代码:keepAliveURL: '/Home/KeepAlive'

            $.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
idleAfter: 600,
keepAliveURL: '/Home/KeepAlive',
pollingInterval: 2,
serverResponseEquals: 'OK',
onTimeout: function () {
window.location = "/Home/Index/";
},
onIdle: function () {
$(this).dialog("open");
},
onCountdown: function (counter) {
$countdown.html(counter); // update the counter
}
});

根据这一行,我返回一条消息“OK”,因为“serverResponseEquals:”正在寻找响应“OK”。我的代码在 MVC 中,所以在“Home” Controller 下我创建了一个返回“OK”的 ContentClass:

   public ContentResult KeepAlive()
{
return Content("OK");
}

成功了,我的页面停止刷新了!

感谢大家对问题的调查!

关于javascript - JQuery idleTimeout 功能中的 "pollingInterval:"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19306262/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com