Welcome Guest, Not a member yet? Register   Sign In
Session data in AJAX Request
#1

[eluser]lookatthosemoose[/eluser]
Are session variables not accessible when calling a controller function via ajax?

For instance, I have an AJAX request that increments a DB field.

The controller function is being called via AJAX, and in that function I'd like to use existing session data, but when I attempt to echo out session variables, I get nothing. See below.

Code:
[removed]
new Ajax("<?=site_url('landing/increment/clickcount')?>").request();

Code:
function increment(){
   echo "userID is: " . $this->session->userdata('user_id');
   $field = $this->uri->segment('3');
   $value = "$field + 1";
   $params = array($field => $value);
   echo $this->respondent->update_field($params);
}

When viewing the AJAX response in Firebug, I only get:
Quote:userID is:

SO does that mean session variables are not available there?
I'm using native sessions not the standard CI sessions.

Thanks

E
#2

[eluser]Pascal Kriete[/eluser]
This should work just fine and I don't know why it isn't working, but there is an easy solution. I assume you're already parsing the javascript due to the fact that you're using site_url. So you could just get it directly from php.
Code:
var user_id = <?= $this->session->userdata('user_id');




Theme © iAndrew 2016 - Forum software by © MyBB