我在会话中存储了5-6个变量值。当我的会话结构即将到期时,我该如何续订它?我正在使用Coldfusion 8。谢谢!
发布于 2011-04-26 03:43:22
使用AJAX ping服务器以保持会话处于活动状态
或者只是简单地延长会话超时timeSpand。
发布于 2011-04-26 04:46:13
从该会话对CFM页面的任何调用都会导致该会话被延长。我所看到的是一个JS计时器将会运行,并在会话到期之前不久结束。当计时器超时时,它会触发一个弹出窗口,该弹出窗口加载一个非CFM页面(Basic HTML),该页面会显示一条关于会话即将结束的消息,并询问用户是否要继续该会话。
发布于 2016-06-22 03:11:36
下面是自动ping服务器的Ajax的概念(如Henry's answer中所建议的)。
//This function will keep the session alive as long as the page is still open.
//Whenever the page nears expiration, it automatically extends it.
function autoExtendSession(days,hours,mins,secs){
var milliseconds = (days*86400000)+(hours*3600000)+(mins*60000)+(secs*1000);
setTimeout(
function(){
$.post("server/heartbeat.cfm");
console.log("Heartbeat sent to the server.");
//Start another timer.
autoExtendSession(days,hours,mins,secs)
//Once we are 98% of the way to the timeout, the heartbeat is sent.
//This way the timeout should never actually be reached.
}, milliseconds-(milliseconds*0.02));
};
hearbeat.cfm
页面实际上不必包含任何内容,当$.post访问它时,服务器将续订会话,无论它是否包含内容。
https://stackoverflow.com/questions/5782420
复制相似问题