jquery - Prevent Ajax Call When there is no session & Network Discoonects in codeigniter -
i facing 2 issues in project.please me rid of those.
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.
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
Post a Comment