标签:
在做登录验证的时候,拦截ajax请求,并给出提示,登录超时
java代码
String requestType = request.getHeader("X-Requested-With");//请求类型 判定是否为ajax请求 if("XMLHttpRequest".equalsIgnoreCase(requestType)){//ajax请求 response.setHeader("sessionstatus", "timeout"); response.sendError(518, "session timeout."); }
js代码
//ajax请求登录验证 $.ajaxSetup({ type: ‘POST‘, complete: function(xhr,status) { var sessionStatus = xhr.getResponseHeader(‘sessionstatus‘); if(sessionStatus == ‘timeout‘) { $.messager.alert("登录失效","由于您长时间未操作,登录已失效,请重新登录","info",function(){ parent.location.href = "login.html"; }); } } });
标签:
原文地址:http://www.cnblogs.com/yyjava/p/5771276.html