Automatic AJAX refresh/update with Prototype’s Ajax.PeriodicalUpdater
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.