I'm writing an AJAX app, but as the user moves through the app, I'd like the URL in the address bar to update despite the lack of page reloads. Basically, I'd like for them to be able to bookmark at any point and thereby return to the current state.
How are people handling maintaining RESTfulness in AJAX apps?
The way to do this is to manipulate
location.hash when AJAX updates result in a state change that you'd like to have a discreet URL. For example, if your page's url is:
If a client side function executed this code:
// AJAX code to display the "foo" state goes here. location.hash = 'foo';
Then, the URL displayed in the browser would be updated to:
This allows users to bookmark the "foo" state of the page, and use the browser history to navigate between states.
Ben Alman's hashchange plugin makes the latter a breeze if you're using jQuery.