AJAX - The Complete Reference

(avery) #1

470 Part II: Developing an Ajax Library^


To get a close-up view of the pretty picture, the user clicks it and a dialog is created showing
the full image. Again, an XHR request is not used, but instead an <img> tag referencing a higher
resolution version of the image is added. Now, we make an architectural decision here not to
call addToHistory() manually since it would not be logical flow to close the large image, hit
back, and be brought back to the large image. Also, we would expect the user to bookmark the
thumbnail and not the full version. This will certainly save them some download aggravation
when they return, but of course it’s at the cost of a click. However, you could certainly modify
this to change the state if you really wanted to.

After dismissing the image, the user hits back and returns to the list of all the items in
the section. For the library to set the state back to normal, it looks at the hash value and
finds the request data stored in the browser’s persistent storage system. Access to this data
is abstracted by the AjaxTCR.storage object. In this particular case, the data is stored to re-
request the page in case some new images have become available in the category. However,
we could have just as easily passed a saveResponse : true in the history object a few
steps earlier, and it would have used the cached data instead. Like deciding which states to
push to history, the question of whether to save the results or re-request them is an
architectural one that you will encounter when you build out your Ajax application.
Free download pdf