Hi guys. I'm still a newbie with ajax and I have a problem that I guess has a standard solution that I don't know.

Here is the situation.
I have my ajax navigation from page to page and I use jQuery and a POST method to send the information to a PHP script. And that works fine. The problem comes when I refresh a page or press the back button on the browser. If I refresh it sends me to my defoult page where I load the PHP scripts and if I press back it goes to the previous website I visited not the previous page I opened in my website.

What is the way to fix the problem. And can you give me some kind of a guide line for Ajax based architectures.

create cookie (ex: lastPageLoaded), and whenever you make an ajax request, upon successful retrieval of your content, update the cookie to the url you used last.

So, upon page load you just need to see if the cookie exists, If yes, load the page/content from whatever url is in the cookie. If not, then load your default page/content.

If you are using jquery, there's a cookie plugin that is very easy to use:
https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.