Ask a Jedi: Updating data and refreshing with Spry

This post is more than 2 years old.

Mark from NZ had an interesting question about Spry:

I have a question regarding Spry, I have a simple dataset, one of the columns is a simple publish button, if on it displays a green image if off red etc. I was wondering if I can create an ajax call whenever the image is clicked it updates the database and dataset to show my changes. At the moment, when it is clicked it browses away from the page performs the update then a cflocation to take you back to show the changes which is a bit cumbersome.

Absolutely! First off - Spry can do calls back to the server for any number of purposes. Sending data back as a FORM post is relatively simple. First start off by reading:

Doing form posts in Spry

This will cover how you can send you data updates back to the server. How do you then refresh the current dataset? The Spry Dataset object has a loadData() method that - well - loads the data. One typical use case is to tweak the URL and reload the data:

dsData.url = "/index.cfm?event=xml.starbuckisntdead"; dsData.loadData();

loadData() by itself should be all you need, but if you run into IE caching issues than you could do the old random number in the URL trick.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Lola LB posted on 4/4/2007 at 9:54 PM

So what do you think happened to Starbucks? Inquiring minds want to know . . .

Comment 2 by Mark Flewellen posted on 4/5/2007 at 5:24 PM

Thanks Ray, I have managed to get the links working as you described above and in the referenced post. I am getting a problem with caching over the red and green images but am sure I will work through that. In the final bit of code where you reload all the data

dsData.url = "/index.cfm?event=xml.starbuckisntdead";

would you just add a javascript random number to the end of the url.

Also is it possible to update just the row with the new information rather than relaoding all the data, or am I getting a we bit ambitious. Anyway really happy to be moving long with spry and should find plenty of uses for it.