window.setInterval(function(){ // call your function here if(ajaxSession(actionUrl)){ //return true, user logged, append/show protected divs. }else{ //return false, remove/hide protected divs and ask user to log. } }, 5000); //every 5 seconds.
ajaxSession函数:
function ajaxSession(actionUrl) { var sessionOK= false; $.ajax({ async: false, url: actionUrl, success: function(msg) { // check the return call from the php file. if(msg== 'OK'){ sessionOK = true; }else{ sessionOk = false; } }}); return sessionOK; }