Jquery空闲计时器激活不触发

我正在使用JQuery空闲时插件在x分钟的空闲时间后自动注销用户。 但是这个空闲/活动时间也应该在服务器中更新。 因此,尝试在active.idleTimer函数内对服务器执行Ajax命中。

 (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);  

但是当用户处于活动状态时,不会调用此active.idleTimer。 我在这做错了什么?

似乎为我工作:

DEMO

尝试将您的代码放在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()); }); });