jquery - Prevent Ajax Call When there is no session & Network Discoonects in codeigniter -


i facing 2 issues in project.please me rid of those.

  1. i using .load() function in javascript load other page using ajax. it's working great. if opened project in other tab , logout , here , try make ajax call showing login page loading page using .load() function.how solve it.

  2. how stop ajax call when network disconnects ?

how solve these 2 issues??

what trying achieve little complex want browser (client) keep record of weather active session current user exists on server.

the problem user's session record maintained @ server , want client know sessions status. need write java script keep calling function on server after fixed interval of time check if session valid.

i :

// call function make request server , check if session exist's after every 10 seconds. var t=setinterval(checksessionexist,10000);   function checksessionexist(){  $.get( "somefunctiontochecksession", function( data ) {    if(!data.issessionactive){      clearinterval(t);      alert("your session has expired. please login continue !!");      location.reload();    } }); } 

on server side have method named somefunctiontochecksession

function somefunctiontochecksession(){   // check user's active session here   $data['issessionactive'] = 0;   if(isset($_session['user_name'])){       $data['issessionactive'] = 1;   }   echo json_encode($data);   } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -