AJAX - The Complete Reference

(avery) #1

PART III


Chapter 10: Web Services and Beyond 533


First, we must initialize the persistence system using the init() method, which returns
a reference to a persistence object we will use later:

var persistObj = AjaxTCR.storage.init();

To add a value to the store, we use the add( ) method, passing it the key and value we
are interested in storing:

AjaxTCR.storage.add("way to a mans heart","his stomach");

In the case of Internet Explorer, we saw, we also needed to pass in the persistence object.
Thus, add( )actually takes that value as well and optionally a storage string value like so:

AjaxTCR.storage.add("way to a mans heart","his stomach",persistObj,"default")

Because of the differing browser needs, we make the assumption that the
persistObject must be passed in and that the store is optional, though it will default to
the value “AjaxTCRStore” when not specified.
To retrieve a value from persistent storage, use the get() method, passing it the key
and persistence object:

var secret = AjaxTCR.storage.add("way to a mans heart",persistObj);
// returned "his stomach"

FIGURE 10-11 Sharing persisted data with Flash storage
Free download pdf