This time I will bring you how to use ajax to jump to the login page when the session times out, and use ajax to jump to the login page when the session times out.What are the precautions? The following is a practical case, let's take a look one time.
Problem: When using window.location.href to jump to the page, the backend only needs to implement a1. Session filter
import java.io.IOException;0 || requestUri.indexOf("/system/login") > 0) { return ; }
Copy after login
2. Add configuration to web.xml:
sessionFilter com.manager.filter.SessionFilter sessionFilter /manager/*
*3 , Rewrite ajax
Note: This code is placed on the index pagejQuery(function($){ var _ajax=$.ajax; $.ajax=function(opt){ var _success = opt && opt.success || function(a, b){}; var _opt = $.extend(opt, { success:function(data, textStatus){ _success(data, textStatus); }, error:function(XMLHttpRequest, textStatus, errorThrown){ //alert(XMLHttpRequest.responseText); //如果请求发生错误,会返回登陆页面源代码,如果源代码里面存在lovnx这个字符串,前端就重定向到登陆页面 var reData = XMLHttpRequest.responseText + ""; if(reData.indexOf('lovnx') != -1) { window.location.href="/manager/login.html" rel="external nofollow" ; return; } } }); return _ajax(_opt); }; });
4. Add code to the login page
How Ajax implements the progress bar of uploading files Codular
Ajax-based formData image and data upload rue implementation
The above is the detailed content of Use ajax to jump to the login page after session timeout. For more information, please follow other related articles on the PHP Chinese website!