重置ajax post之间的idleTimeout计数器
Reset idleTimeout counter between ajax post
我在这里使用JQuery idleTimeout插件:
http://www.erichynds.com/examples/jquery-idle-timeout/example-mint.htm我在mvc 4应用程序中使用它。
下面是我设置会话计时器的代码片段。
<script type="text/javascript">
var sessionTimer = 60;
$(document).ready(function ()
{
// 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);
}
}
});
var $countdown = $("#dialog-countdown");
@* start the idle timer plugin *@
$.idleTimeout('#dialog', '#dialog-button-yes', {
idleAfter: (sessionTimer - 30),
keepAliveURL: '@Url.Action("KeepAlive", "Home")',
pollingInterval: 5,
serverResponseEquals: 'OK',
AJAXTimeout: 250 * 60,
onTimeout: function () {
window.location = '@Url.Action("Logout", "Login")';
},
onIdle: function () {
$(this).dialog("open");
},
onCountdown: function (counter) {
$countdown.html(counter); @* update the counter *@
}
});
});
这段代码位于最外层/共享视图中。我所有的页面都是使用jquery $.ajax的部分视图加载的。上面的代码只加载一次,sessionTimer被设置为60秒。因此,当调用ajax post加载新页面时,计时器不会重置。即使用户处于活动状态,计时器也会在帖子之间滴答作响。是否有一种方法让我重置计数器每次ajax帖子发生。我可以在每个inner views $上重置这个。Ajax成功条件。但是有太多的地方。我想知道是否有一个共同的代码,我可以在我的这个主页上写,这将让我知道一个ajax调用已经放置,并重置计数器。
尝试使用来自jQuery的.ajaxSuccess()
事件处理程序。您可以在这里查看如何使用它的文档:http://api.jquery.com/ajaxsuccess/.
相关文章:
- JQuery使计数器每次更改时都会增加
- Javascript计数器变量未显示正确的值
- 带有计数器、缩略图、进度条和淡入淡出效果的简单jQuery幻灯片
- 如何在for循环中使用计数器
- 正确使用AES-CTR模式的随机数和计数器
- Javascript猜测游戏-计数器不工作
- Javascript第二计数器
- Jquery:直到寄存器打开的时间计数器
- 如何使用JavaScript创建时间计数器
- Javascript计数器问题
- 类似按钮增量计数器不工作.PHP,AJAX,MySQL,javascript
- 如何正确制作计数器angularjs
- 使用FlipClock js的404页面计数器效果
- (PHP)克隆按钮上的按钮点击计数器
- 困在使用RxJS删除所有计数器应用程序中
- JavaScript中的足球时钟计数器
- 键入时更改计数器的颜色
- Highcharts车速表,里程计数器的数据标签
- 函数式编程 - 用于递增计数器的简单 for 循环
- 重置ajax post之间的idleTimeout计数器