我正在使用 JQuery 空闲时间插件在 x 分钟的空闲时间后自动注销用户。 但是这个空闲/事件时间也应该在服务器中更新。因此尝试在 active.idleTimer 函数内对服务器进行 Ajax 命中。
<script type="text/javascript">
(function ($) {
var timeout = 1800000;
$(document).bind("idle.idleTimer", function () {
window.location.href = "MyLOGOUT_URL";
});
$(document).bind("active.idleTimer", function () {
$.ajax({ type: "POST", url : "My_URL" });
});
$.idleTimer(timeout);
})(jQuery);
</script>
但是当用户处于事件状态时,不会调用此 active.idleTimer。我在这里做错了什么?
最佳答案
似乎对我有用:
尝试将代码放入 jQM pageinit 事件中并使用 .on() 而不是绑定(bind):
$(document).on("pageinit", "#page1", function(){
$( document ).idleTimer( 5000 );
$( document ).on( "idle.idleTimer", function(){
$("#textinput-1").val('Idle at: ' + new Date());
});
$( document ).on( "active.idleTimer", function(){
$("#textinput-1").val('Active again at: ' + new Date());
});
});
关于javascript - Jquery 空闲计时器事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21193593/