【问题标题】:CodeIgniter Session Out Not Working While Background AJAX Call Running With 5 seconds IntervalCodeIgniter 会话不工作,而后台 AJAX 调用以 5 秒的间隔运行
【发布时间】:2019-06-15 15:13:36
【问题描述】:

后台 AJAX 调用以 5 秒间隔运行时,CodeIgniter 会话不工作。已使用 Javascript setInterval() 函数设置间隔。 Session Out 将如何处理自动 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项目的配置文件

【问题讨论】:

    标签: ajax session codeigniter-3


    【解决方案1】:

    我已经尝试了下面的代码,它对我有用。

    var inactiveTime = 1200000; //20 分钟

    var 交互事件 = [ “负载”, “鼠标移动”, "onmousedown", "ontouchstart", “点击”, “滚动”, “按键” ]; 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();
    

    【讨论】:

      猜你喜欢
      • 2011-12-20
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-13
      相关资源
      最近更新 更多