Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:21:38+00:00 2026-06-08T14:21:38+00:00

Am I doing something wrong with the following code? I can’t seem to get

  • 0

Am I doing something wrong with the following code? I can’t seem to get alert(“success”) to process when the Ci session expires. Below is my jquery and Ci code:

setInterval(function() {
    jQuery.getJSON("<?=base_url()?>index.php/regUserDash/sessionExpire", function(data) {
        var sessionState = jQuery.parseJSON('{"sessionExpired":"true","sessionExpired":"false"}');
        if(sessionState.sessionExpired === "true") { // if session is expired run the following code
            var dataString = 'true';
            jQuery.ajax({   // send the expired signal to Ci so that it knows the session has expired
                type: 'POST',
                dataType: 'JSON',
                url: '<?=base_url()?>index.php/regUserDash/extendSession',
                data: {'dataString': true},
                success: function(data) {
                    if (data.extendedSession == true) {
                        alert('success');
                    } else {
                        return false;
                    }
                }
            });
        } else if(sessionState.sessionExpired == "false") {
            return;
        }
    });
}, 120000); // loop through every 2 minutes

CodeIgniter Code:

public function sessionExpire() {
        if ($this->session->userdata("logged") == "1") {
            echo json_encode(array("sessionExpired" => false));
        } elseif($this->session->userdata("logged") == "0") {
            echo json_encode(array("sessionExpire" => true));
        }
    } public function extendSession() {
        // set loggedIn session var
        $this->session->set_userdata('logged', '1');
        // return json to ajax call
        echo json_encode(array("extendedSession" => true));
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:21:41+00:00Added an answer on June 8, 2026 at 2:21 pm

    jQuery.parseJSON('{"sessionExpired":"true","sessionExpired":"false"}'); return first sessionExpired = true and second sessionExpired = false, which overwrite the first.

    So, here is one way to do this (need test):

    setInterval(function() {
        jQuery.getJSON("<?=base_url()?>index.php/regUserDash/sessionExpire", function(data) {
            if(data.sessionExpired == "true") { // if session is expired run the following code
                // var dataString = 'true'; // Remove this
                jQuery.ajax({   // send the expired signal to Ci so that it knows the session has expired
                    type: 'POST',
                    dataType: 'JSON',
                    url: '<?=base_url()?>index.php/regUserDash/extendSession',
                    data: {'dataString': true},
                    success: function(data) {
                        //if (data.extendedSession == true) {
                            alert('success');
                        //} else {
                        //    return false;
                        //}
                        // Remove commented code, because extendSession() always return true
                    }
                });
            } else {
                return 'Session not expired!';
            }
        });
    }, 120000); // loop through every 2 minutes
    

    And CI functions:

    public function sessionExpire()
    {
        if ($this->session->userdata("logged") == "1") {
            echo json_encode(array("sessionExpired" => false));
        } elseif ($this->session->userdata("logged") == "0") {
            echo json_encode(array("sessionExpired" => true));
        }
    }
    
    public function extendSession()
    {
        // set loggedIn session var
        $this->session->set_userdata('logged', '1');
        // return json to ajax call
        echo json_encode(array("extendedSession" => true));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So obviously I am doing something wrong, but I just cannot seem to get
I guess I'm doing something wrong with my includes but I just can't seem
Perhaps I am doing something wrong while z-normalizing my array. Can someone take a
Am I doing something wrong if I need code like this in a Controller?
I know I'm doing something wrong, but I can't figure out what I'm doing
I'm sure I'm doing something stupid here, but the following code: ... public void
I must be doing something wrong here but I can't find an easy way
I have the following code example below. Whereby you can enter a command to
I must be doing something wrong here. I'm trying to use Google Analytics to
(Maybe I am doing something wrong but) I am getting awful read performance from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.