Created
May 22, 2012 21:38
-
-
Save legierski/2771769 to your computer and use it in GitHub Desktop.
js for am-i-logged-in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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'); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't it be easier to pass the function object:
setInterval(am_i_logged_in, 60000);