我从这里使用 JQuery idleTimeout 插件:
http://www.erichynds.com/examples/jquery-idle-timeout/example-mint.htm
当我在我的代码中实现时它工作得很好,但是每当我启动我的页面时,它每次都会刷新 5 次,所以我通过删除 idleTimeout 代码进行检查。然后它没有给出这个问题。
详细介绍后,我发现如果我删除或注释“ pollingInterval:2
”行代码,一切正常,刷新问题解决,超时功能仍然有效。
有人可以帮助我了解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
如果您需要任何其他信息,请告诉我!
请建议!