
Request.Periodical.js extends Request, Request.HTML, and Request.JSON to add methods that periodically request the same URL but increase the interval if no data is returned from the server. This helps reducing load on a server and prevents pointless requests. If any valid response data is returned it resets the interval and executes more requests again.
var myRequest = new Request(options); myRequest.startTimer(data);
new Request({ method: 'post', url: 'foo.php', initialDelay: 1000, delay: 5000, limit: 15000 }).startTimer({ myData: 'value' }); // Requests foo.php via post and the provided data initially a second after // calling the start method. If any valid response data is returned it requests // every five seconds. If no data is retrieved it adds five seconds to the // interval until the next request that returns data resets the interval. // This example uses a limit so the maximum interval will be 15 seconds.
Starts requesting the URL given by the initial options
myRequest.startTimer(data);
var foo = new Request({url: 'foo.php'}); foo.startTimer({myData: 'value'});
Stops the timer and does not execute any more requests beside an already running request.
myRequest.stopTimer();
© Linux.ria.ua, 2008-2024 |