One way is to have a script that just pings the page to see if it will still be running, but that will increase the number of AJAX requests that you will need to make.
Another option is complete $.ajax()to check the HTTP status code on the XMLHttpRequest object, which is passed to:
$.ajax({..., complete = function(xhr, textStatus){
if(xhr.status > 300 && xhr.status < 400)
window.location.href = '/login/';
...
}, ...);
source
share