Skip to content

Instantly share code, notes, and snippets.

@legierski
Created May 22, 2012 21:38
Show Gist options
  • Save legierski/2771769 to your computer and use it in GitHub Desktop.
Save legierski/2771769 to your computer and use it in GitHub Desktop.
js for am-i-logged-in
$(document).ready(function() {
am_i_logged_in_interval = setInterval("am_i_logged_in()", 60000);
});
function am_i_logged_in() {
address = window.location.protocol+'//'+window.location.hostname+'/am-i-logged-in';
$.ajax({
type: "POST",
url: address,
success: function(data) {
try{
response = $.parseJSON(data);
if(response.success == true) {
// good, user is logged in!
}
else {
notify('Oops! You might be logged out, please, back up your content and refresh the page!', 'long');
}
}
catch(err) {
alert('Oops! An error: '+err.message, 'error');
}
}
});
}
@FND
Copy link

FND commented May 24, 2012

setInterval("am_i_logged_in()", 60000);

Wouldn't it be easier to pass the function object: setInterval(am_i_logged_in, 60000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment