AJAX - The Complete Reference

(avery) #1

PART II


Chapter 9: Site and Application Architecture with Ajax 473


Ajax and Bookmarking


Given that a new URL is being set and now we are moving through history properly, it
would seem that the bookmarking problem would also be solved. Not quite: this problem
depends a bit on what the bookmark records and what is necessary in your app to rebuild
the application. Consider what happened in Figure 9-14.
What happened here is that the URL value was not enough to reconstruct the page since
the persistent storage was needed as well. This could happen more often than you think.
Maybe you are using a different browser, maybe you cleared your private data, or maybe
you simply sent the URL to a friend and they tried to access the page. In any case, we are
stuck unless the URL contains enough data in it to set things right.
If the state of the application is recorded truly in the URL, then the callback that is set in
the history init()should be able to rebuild the page. If the state of the application isn’t
stored properly in the URL, you are stuck, but is this surprising? Consider that this is the
same concern we would find with a traditional Web application. If you had a “dirty URL”
like this:

http://ajaxref.com/ch9/sampletraditionalapp.php?stateval=5&user=thomas

It contains all the necessary information to return the page to the state. If the application
had been using clean URLs, relying on POST, and storing state information using session
cookies, the URL might look more like this:

http://ajaxref.com/ch9/sampletraditionalapp.php

FIGURE 9-14 Bookmarks aren’t transportable?
Free download pdf