简体   繁体   中英

jquery ajax calls form authentication issue

I am making jquery ajax calls to server after each 10 seconds from a page. Now when a user makes normal request (no ajax call) to server (if he stays idle for 2 minutes) I want the user to become log out. I have already made a form authentication cookie with timeout 2 minutes but the issue is that automatic jquery ajax calls(after each 10 seconds) are not making the user unauthenticated. How can I handle this case.

Clear the interval and remove the authentication cookie after 2 minutes :

var intervalID=window.setInterval(yourajaxfunction,10000);

window.setTimeout(  
    function() {  
        clearInterval(intervalID);   // cancel the ajax requests
        clearCookie(); // remove the authentication cookie locally
    },  
    120000  // 2 minutes timeout
);

I'm guessing that on the server side there is a check for the authentication cookie - if its not found then the user is forced to re-authenticate.

You can make a validation function @ server side . every ajax request call this validation first and if valid execute your script normally . if not valid you can clear cookies .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM