Using javascript for pinging a webapp to keep session open

santi picture santi · May 11, 2009 · Viewed 24.1k times · Source

I'm writing a greasemonkey script to keep session open on a webapp I use for work. Which javascript command would you use to create some feedback with the server and ensure the session doesn't fall without having to bother the user making a complete refresh of the page?

Answer

santi picture santi · May 11, 2009

I've solved the issue using:

function keepAlive() {
    var httpRequest = new XMLHttpRequest();
    httpRequest.open('GET', "/restricted_file_url");
    httpRequest.send(null);
}

setInterval(keepAlive, 840000);  //My session expires at 15 minutes