jQuery keepalive Plugin Demonstration & Documentation

Version: 1.0
Date: 26 August 2010
License: MIT License or GNU General Public License (GPL) Version 2
Git repository: [ http://github.com/waynewalls/jquery.keepalive ]

Background. This plugin sends ajax requests to the server at configurable intervals to keep a PHP session from expiring.

Limitations. none.

How to use this demonstration. jQuery.keepalive is started automatically. The default interval for contacting the server is 5-minutes. Since keepalive does no error checking on the ajax request (in order to keep keepalive as unobtrusive as possible), the 5-minute interval allows 2 failed keepalive connections in a row while still maintaining a 20-minute contact interval—which keeps most PHP sessions from expiring. For debugging purposes you can toggle a status display which is appended to the body element (The toggle option below relays the status display just to the right of the button). (Your browser appears to have cookies disabled. Session cookies are required for the keepalive plug-in.)

Select an option...


jQuery.keepalive dependencies:
requires jQuery v1.4; there are no other dependencies.
jQuery.keepalive usage:
jQuery.keepalive is started automatically when the plug-in is included a page.
$.keepalive.configure( config )
where config is an object containing keepalive options.
$.keepalive.stop()  // stop the keepalive interval timer
$.keepalive.start( config )  // start the keepalive interval timer
where config is an optional object containing keepalive options.
$.keepalive.toggleDisplay()  // toggle the keepalive status display
the status display is appended to the body element
jQuery.keepalive options (type) [ default value ]:
$.keepalive.options.url (string) [ "php/keepalive.php" ]
The URL to assign to the $.ajax() URL property
$.keepalive.options.dataObject (object) [ { id:"keepalive" } ]
An object to be assigned to the $.ajax() data property
$.keepalive.options.interval (integer) [ 300000 ]
The interval between requests to the server in milliseconds (default is 5-minutes)
$.keepalive.options.timeout (integer) [ 20000 ]
An integer to be assigned to the $.ajax() timeout property
$.keepalive.options.errorCallback (function()) [ null ]
A function that will be called when the keepalive $.ajax() request returns an error.
$.keepalive.options.successCallback (function()) [ null ]
A function that will be called after each successful keepalive $.ajax() request.
jQuery.keepalive public methods:
$.keepalive.configure( config )
sets keepalive options where config is an object containing new options that will act as default values for subsequent ajax requests.
$.keepalive.stop()
Stops the keepalive interval timer.
$.keepalive.start()
Starts the keepalive interval timer.
$.keepalive.toggleDisplay()
Toggles the keepalive status display. The display is appended to the body element.