A very common problem, if you visit the website session expires, the user needs to return to the login page to log in again.
If http request can be set in the background Interceptor, unification interception and jump. However ajax method does not pass the background jump directly.
So we can write a global ajax method, so that every ajax request to have access to this method, after determining if the session expired, you can jump to the login page.
The following is a reference to the jQuery ajax global method:
.ajaxSetup $ ({ error: function (X, Status, E) { IF (x.status == '403' ) { Alert ( '! You do not have permission to perform this operation' ); } the else { the console.log ( 'system ! error, please contact the administrator ' ); } return to false ; }, Complete: function (R & lt, S) { var istimeout = r.getResponseHeader (' sessionstatus') == 'timeout' ; IF (istimeout) { // Alert (r.responseText); var loginUrl = r.getResponseHeader ( "loginUrl"); parent.window.location = loginurl; } } });
I was doing this project when it uses vue, so the global ajax method vue also write about
Vue.http.interceptors.push(function(request) { // modify request request.method = 'POST'; // return response callback return function(response) { var sessionAjax = response.headers.map.sessionstatus; if (sessionAjax != undefined) { var loginurl = response.headers.map.loginurl[0]; parent.window.location = loginurl; } }; });