简体   繁体   中英

How to keep session alive in angular JS

I am working on web application in which we have angularJS as UI and java as back end. We have configured tomcat server session timeout to 20 minutes. AngularJS is responsible for fetching and saving data. When the data size is huge sometime it takes more than 20 minutes to process the request which is fine as per our business requirement.

We are facing issue if any ajax request takes more than 20 minutes. Whenever any operation takes more than 20 minutes session goes timeout however angularJS still waits for data to be returned. ajax request to server is not able to keep session alive. We checked it by opening a new tab in browser it asks for login where first tab waits for data to be returned.

Is there any way to keep the session alive till the server processing the request.

Below is my angularJS code to make request to server.B

return $http({
            method: method,
            url: url,
            async:true,
            data: $.param(data),
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
                'X-Requested-With':'XMLHttpRequest'
            }
        }).then(function(response){
           if(response.status ===200){
                // do  some work
           }               else{
               failureCallBack(response.data, response.status, response);
           }
        });

You can configure angular timeout:

From $http docs: timeout – {number|Promise} – timeout in milliseconds, or promise that should abort the request when resolved.

Use angular keep alive

$scope.$on('Keepalive', function() {
    // do something to keep the user's session alive});

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