Skip to content

Instantly share code, notes, and snippets.

@edgargoncalves
Created June 18, 2010 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edgargoncalves/443075 to your computer and use it in GitHub Desktop.
Save edgargoncalves/443075 to your computer and use it in GitHub Desktop.
var pingTimer = null;
var pingServer = function () {
//make a background server request to a ping service
var x = $("<script/>", {src: "/servlet/ping"});
$("body").append(x);
x.remove();
};
var resetPingTimer = function () {
if (pingTimer !== null) {
clearInterval(pingTimer);
}
pingTimer = null;
pingTimer = setInterval(pingServer, 120000); //2mins
};
var ajaxStopHandler = function() {
resetPingTimer();
};
$.ajaxStop(ajaxStopHandler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment