CodeIgniter会话在后台AJAX调用以5秒间隔运行时无法正常工作。已使用Javascript setInterval()函数设置了时间间隔。会话输出如何与自动Ajax调用一起工作?
JavaScript代码:
setInterval(function() {
$.ajax({
url: '../Sadmin/getNotification',
beforeSend: function(){
},
type: 'POST',
dataType:'json',
success: function(response){
if(response.inactive_users.inactive_user=='0'){
$("#inactive_user").removeClass('notify');
}else{
$("#inactive_user").text(response.inactive_users.inactive_user).addClass('notify');
}
if(response.inactive_cp_users.inactive_user=='0'){
$("#inactive_cp_users").removeClass('notify');
}else{
$("#inactive_cp_users").text(response.inactive_cp_users.inactive_user).addClass('notify');
}
if(response.inactive_bp_users.inactive_user=='0'){
$("#inactive_bp_users").removeClass('notify');
}else{
$("#inactive_bp_users").text(response.inactive_bp_users.inactive_user).addClass('notify');
}
if(response.pending_coupon==''){
$("#pending_coupon").removeClass('notify');
}else{
$("#pending_coupon").text(response.pending_coupon).addClass('notify');
}
if(response.pending_bp_coupon==''){
$("#pending_bp_coupon").removeClass('notify');
}else{
$("#pending_bp_coupon").text(response.pending_bp_coupon).addClass('notify');
}
if(response.pending_cp_coupon==''){
$("#pending_cp_coupon").removeClass('notify');
}else{
$("#pending_cp_coupon").text(response.pending_cp_coupon).addClass('notify');
}
if(response.complaints_no=='0'){
$("#complaints_no").removeClass('notify');
}else{
$("#complaints_no").text(response.complaints_no).addClass('notify');
}
},
});
}, 5000);
config.php:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 300;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
codeigniter项目的此配置文件
答案 0 :(得分:0)
我已经尝试过下面的代码,并且对我有用。
var inactiveTime = 1200000; // 20分钟
var interactionEvents = [ “负载”, “ onmousemove”, “ onmousedown”, “ ontouchstart”, “ onclick”, “缠卷”, “按键” ]; var timeoutId = null;
var finished = function () {
window.location='Superadmin/Logout';
console.log("User inactive.");
};
var hasFinished = false;
var reset = function () {
if (hasFinished === true) {
return;
}
clearTimeout(timeoutId);
timeoutId = setTimeout(function () {
hasFinished = true;
if (typeof(finished) === "function") {
finished();
}
}, inactiveTime);
for (var i = 0, max = interactionEvents.length; i < max; i++) {
document[interactionEvents[i]] = reset();
}
};
reset();