简体   繁体   English

如何通过使用jQuery Ajax调用来防止会话超时?

[英]How to prevent session timeout by using a jQuery Ajax call?

I try to put following code into bottom of HTML page: 我尝试将以下代码放入HTML页面的底部:

<script type="text/javascript">
var refreshTime = 300000;
    window.setInterval( function() {
        $.ajax({
            cache: false,
            type: "GET",
            url: "custom url",
            success: function(data) {
            }
        });
    }, refreshTime );
</script>

And I need when it exceed session time (30000 ms), then refresh with "custom url". 我需要超过会话时间(30000毫秒)的时间,然后使用“自定义网址”刷新。

But as I try, the page wouldn't refresh or redirect with "custom url" after pass 30000 ms or 5 minutes. 但是,正如我尝试的那样,经过30000毫秒或5分钟后,该页面不会刷新或使用“自定义网址”重定向。

Am I correct to do this? 我这样做正确吗?

Thanks 谢谢

You can do the following in success function of ajax call: 您可以在ajax调用的成功功能中执行以下操作:

setTimeout(function() {
    window.location.href = 'your-url-here';
}, 2000);

You have not implemented any reload function. 您尚未实现任何重新加载功能。

var refreshTime = 300000;
    window.setInterval( function() {
      location.reload();//reload 
// window.location.href = "custom url"; to redirect

 }, refreshTime );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM