Link to home
Create AccountLog in
Avatar of dolythgoe

asked on

Going back on the browser and your page being remembered in its AJAX state

Hi all,

I have a page which has some inner AJAX filteration features which obvious doesn't change the main URL.

I want to remember the 'state' of the page and which options were picked when the user comes back to the page using the back button.

PHP can set the page ok aslong as the variables in the URL are set but because AJAX performs some functions before the user disappears I'm not sure how to set the page up for return 'back' visitors.

It's an important feature I'd like to work towards so if anyone has experience in this or is a common combatted issue would love to get some help :)

Avatar of COBOLdinosaur
Flag of Canada image

If ajax is changing the state, then you need to preserve it before ajax can do that.  Save it to the cookie or worst case keep on the database as an active session.  Cookie is better because DB would require cleanup for those who do not come back.

Avatar of p_nuts
The problem is that the browser doesn't do a call to the webserver when clicking the back button

The easiest way is to set all the filter options in a session using PHP and using Ajax to check the session cars on document load. That way the page will go back and Ajax will check the session and load the filters.
Avatar of dolythgoe


Ah ok,

Let me see if I've got this right...

So it won't request from the webserver but javascript will run again? So I can use ajax to call the webserver when it does?

Keep all options in a $_SESSION which is populated via ajax when options are being applied and then called again via AJAX when the user comes back.

The key here is that Javascrip runs afresh on going back..?
Avatar of p_nuts
Flag of Netherlands image

Link to home
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer about setting something up on outbound links to set the URL with all the options first before redirecting? Feasible..?
Consider using sessions to store the data on the current page and then when the user go to another page and get back to the old one, the page will reload the information from sessions.
Thanks for all the help - I used this plugin in the end:

Really useful :)