我有一个ColdFusion页面,用户可以打开一个模态并查看有关一行数据的更多信息.但是,如果用户在页面上的时间超过默认的20分钟会话超时,则会抛出错误,因为它正在查找会话变量但无法找到它们.我理解如何使用服务器端代码捕获这个,但我似乎无法通过
AJAX调用来成功确定会话是否仍然存在.
这是当用户点击按钮打开模态时触发的AJAX代码.基本上它正在检查会话是否与CFC中的函数一起存在.我的问题是,它总是返回’有效’.
//this checks if the session is expired
function checkSessionExists() {
$.ajax({
//this is the that has function
url: 'components/Admin.cfc',//POST method is used
type: "POST",//pass the data
data: {
method: "checkSessionExists"
},async: false,success: function(response) {
//$('#loading').hide();
var obj = $.trim(response);
if (obj == 'expired') { //it's never expired
alert('Sorry,your session has expired.')
window.location.href = "logout.cfm";
return false;
}
else{
}
},error: function(jqXHR,exception) {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
});
return false;
}
这是CFC中的功能:
我想当我问CFC会话是否存在时,它仍然有会话变量,因为页面在20多分钟内没有刷新.所以…想知道如何向CFC发送AJAX请求并在CFC中有一个功能重新评估会话变量.任何帮助将不胜感激!