A port of Prototype's Ajax.PeriodicalUpdater
function to jQuery.
Basically, this function polls some remote service at fairly regular internvals, and (optionally) processes the result via a callback. The period of calls will decay as long as the same response keeps coming back from the server (either in the form of repeated data or in the form of a 304 Not Modified status), which reduces the load on the server naturally. The first Ajax call happens as a page 'onReady' handler $(function), so it is safe to put the PeriodicalUpdater call anywhere on the page.
Usage:
The "data" value can be one of three things:
- A scalar, in which case it will be used constantly.
- A map/object, in which case it will be turned into key/value pairs by jQuery
- An anonymous function, in which case it will be executed before each AJAX call
Any of the other standard $.ajax configuration options can be passed to the setting map.
The only exception is the flag that treats modifications as errors. That’s always
going to be 'true'.
The function call returns a handle. You can call .stop()
on this handle in order to stop
the updating and ignore any subsequent responses. If the maximum number of calls, .stop()
, or
the autoStop has been triggered, you can restart the updater using .restart()
on the handle.
More info, including advantages over 360innovate version:
See the source file for license terms.