Posts Tagged ‘refresh’

Automatic AJAX refresh/update with Prototype’s Ajax.PeriodicalUpdater

Posted on 2008.11.21 by Tony G.

The Prototype javascript library has a tight little method called Ajax.PeriodicalUpdater which will periodically perform an Ajax request at specified intervals. The format is nice and simple:

    var adbox = new Ajax.PeriodicalUpdater('adbox', 'http://'+location.host+'/ad',//the url
                     {method: 'get', frequency: 5}//this is the number of seconds.
                );

In other words:

    var updatername = new Ajax.PeriodicalUpdater('divid', 'url',
                     {method: 'get', frequency: seconds}
                );

Its a good idea to use location.host to build the URL as visitors may access your domain directly instead of using www, etc.

Bookmark and Share