Сеанс CodeIgniter не работает во время фонового вызова AJAX с интервалом 5 секунд - PullRequest
0 голосов
/ 14 июня 2019

Сеанс 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

1 Ответ

0 голосов
/ 15 июня 2019

Я попробовал приведенный ниже код, и он работает для меня.

var inactiveTime = 1200000; // 20 минут

var взаимодействияEvents = [ "в процессе", "OnMouseMove", "OnMouseDown", "Ontouchstart", "по щелчку", "OnScroll", "OnKeyPress" ]; 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();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...