0

I've looked around, but I can't seem to find a solution.

I have a drop down menu in my html and when you select one of the option it redirects to a different url in my jquery.

like this

$('#chapter').change(function(){
  var chapter = $(this).val();
  $(location).attr('href','http://www.writeyourfiction.com/story/readStory/'+chapter);
}); 

This all works fine, but my issue is when that redirect happens codeigniter seems to be dropping my sessions. I've var_dumped my sessions before the redirect and they are there, but when I ver_dump them again after the redirect the sessions are empty.

Any help would be amazing!

zazvorniki
  • 3,512
  • 21
  • 74
  • 122
  • Why are you using the complete url? Perhaps your session is on another (sub-) domain? – jeroen Jun 15 '13 at 00:26
  • because I thought you had to with a jQuery redirect.... I can't believe I didn't try erasing that before...wow...and now it works! Thank you for correcting my very silly moment! – zazvorniki Jun 15 '13 at 00:33

2 Answers2

0

I think so the session class must either be initialized in your controller constructors,by use the $this->load->library('session'); function, Or If sessions data does not exist (or if it has expired) a new session will be created and saved in the cookie.

timmz
  • 2,194
  • 3
  • 23
  • 29
  • I got it to work, thank you for the answer. My problem was I was putting the whole url in the jquery redirect when I should have just put the controller and function. Silly move on my part! – zazvorniki Jun 15 '13 at 00:34
  • good, if you face the problem with CI session just check this fabulous answer: http://stackoverflow.com/questions/7980193/codeigniter-session-bugging-out-with-ajax-calls?lq=1 – timmz Jun 15 '13 at 00:40
  • I actually already looked at that! Thank you for posting it though, it's a very good thing to read...anyone using ci and jquery should read it! – zazvorniki Jun 15 '13 at 00:42
0

It is better to load your session library in /application/config/autoload

for jquery with codeigniter drop down you could do something like this i used jQuery Ajax: here is the code example:

<select name="all_users" id="all_users" onchange="javascript:cal_ajax(this.value);">
  <?=$my_option_list?>
</select>

<script type="text/javascript">
var base_url = '<?=base_url()?>';

function cal_ajax(id)
{ 
    $.ajax({
    type:"POST",
    url: base_url+"history/home/get_users",
    data: "userid=" + id,
    success: function(result){
        $("#Mehdi_ajax").html(result);
    }
    });

}
</script>

in our controller function for example here in function get_users() you set your redirections

MJ X
  • 8,506
  • 12
  • 74
  • 99