I have a simple website ( http://www.kousenit.com/twitterfollowervalue ) that calculates the amount based on Twitter subscribers. Because the Twitter API only returns 100 followers at a time, the complete process can involve many calls.
At the moment, I have an Ajax call for a method that starts a Twitter loop. The method looks like (Groovy):
def updateFollowers() { def slurper = new XmlSlurper() followers = [] def next = -1 while (next) { def url = "http://api.twitter.com/1/statuses/followers.xml?id=$id&cursor=$next" def response = slurper.parse(url) response.users.user.each { u -> followers << new TwitterUser(... process data ...) } next = response.next_cursor.toBigInteger() } return followers }
This is called from a controller called renderTTFV.groovy. I call the controller through an Ajax call using the prototype library:
On my webpage in the header section (JavaScript):
function displayTTFV() { new Ajax.Updater('ttfv','renderTTFV.groovy', {}); }
and there is a div in the body of the page, which is updated after the call is completed.
Everything works, but the updateFollowers method can take a lot of time. Is there a way to bring back the meaning of progress? For example, I would like to refresh a webpage at each iteration. I know in advance how many iterations will be. I just can't figure out how to refresh the page in the middle of this loop.
Any suggestions would be appreciated.
javascript prototypejs ajax progress-bar groovy
kousen Apr 03 '10 at 22:09 2010-04-03 22:09
source share