Hi Guys so i am developing an app in Codeignitor. content is updated based on three select tags. First one city which populates locality select tag for that city and at the same time makes category select tag visible.
Have successfully setup for bunch of ajax calls. content is updated according to the ajax call. Now I click on the content link to view the content. success… but when i hit back button of the browser I get messed up select tags.
So then I realized that I need a session variable so that when user hits back button of browser I can keep him at the same select tag stage. I am able to successfully store the session lets say city for the moment.
then I used
$(document).ready(function () {
$city="<?php echo $this->session->userdata('city'); ?>";
alert($city);
});
to check if everything is ok or not. Now the problem is that
Los Angeles(LA):1
London:2
scenario 1:
I select LA then look at loaded content click to view the content then hit back button of browser then get blank alert box. But if i reload then I get alert with 1 in it
scenario 2 after scenario 1:
I select LA then London view content then come back and I see 1 in alert box. I reload the page i see 2 in alertbox
So I dug into this linkand found the cause of the problem… looks like refreshed session is only served on the next server request. AS you can see my problem i want that refreshed info so that i can keep my users at the same state where they left off.
Any suggestions on how I can solve this problem?
That is how cookies work. The are send with the request from the clientside.
A workaround is to set the
$_COOKIEvariable manually:UPDATE
Now that I think I misunderstood your question. It looks like you are having an issue when using the browsers back button? Is that correct? If so you will always get the previous state of the page and the cookie will indeed not be set (because it will retrieve it from the browsers cache). The only way I see this will ever work is either by refreshing the page through some script (i.e. JS), but that will be annoying. Or retrieve the cookie value through an AJAX call (new request) to the server.