我正在使用表单身份验证,并且超时为30分钟。
我正在寻找的是一些方法,提示用户只需几分钟就能完成他们即将超时,以及他们是否希望让他们的会话保持活力。
我们有一些相当大的表单,用户填写了大量数据。他们一直在检查其他系统的信息,与同事通过电话交叉检查等等。
我也希望在超时之前添加自动保存。
例如,使用JQuery实现这些简单的事情吗?
答案 0 :(得分:2)
我们在项目中找到的解决方案是创建一个javascript(不一定是jQuery),在用户注销之前会提示用户,并发送伪造的httpRequest以保持会话处于活动状态。
我们的脚本就像(未经测试):
var promptUserTimeoutId = 0;
promptUserTimeoutId = setTimeout(promptUser, 30 * 60 * 1000); //call just once, in 30 minutes
function promptUser() {
if (alert('stay logged in?')) {
sendHttpRequest(); //just signal a keep-alive to the server...
//re-set the 30 minutes count
clearTimeout(promptUserTimeoutId);
promptUserTimeoutId = setTimeout(promptUser, 30 * 60 * 1000);
}
}
答案 1 :(得分:1)
function keepSessionAlive(timeLeft)
{
var timer = setTimeout(function(){
//Prompt the user to keep the session alive;
//make a dummy request via ajax to refresh the session on the server.
//reset the timeLeft to your timeout
//call keepSessionAlive(timeLeft)
},timeLeft);
}
然后在文档加载时,您可以调用您的方法。
body.onload=keepSesionAlive(<yourTimeOut-3 to 4 minutes>);
我不知道这样做的jquery方式。