• 重写ajax方法实现异步请求session过期时跳转登录页面


       
     4 jQuery(function($){
     5 
     6             // 备份jquery的ajax方法 
     7             var _ajax=$.ajax;
     8             // 重写ajax方法,
     9             $.ajax=function(opt){
    10                 var _success = opt && opt.success || function(a, b){};
    11                 var _error = opt && opt.error || function(a, b){};
    12                 var _opt = $.extend(opt, {
    13                     success:function(data, textStatus){
    14               // 如果后台将请求重定向到了登录页,则data里面存放的就是登录页的源码,这里需要判断(登录页面一般是源码,所以这里只判断是否有html标签)
    15                         if(data.meta.code == 返回的需要登录的状态码) {
    16                             alert('请先登录!');
    17                             window.location.href = "login.html";
    18                             return;
    19                         }
    20                         _success(data, textStatus); 
    21                   },
    22                   error:function(data, textStatus){
    23                     if(data.meta.code == 返回的需要登录的状态码){
    24                       alert('请先登录!');
    25                       window.location.href = "login.html";
    26                       return;
    27                     }
    28                     _error(data, textStatus);
    29                   }
    30                 });
    31                 return _ajax(_opt);
    32             };
    33         });
    34  
    35       
  • 相关阅读:
    OC
    OC
    OC
    OC
    OC
    Oracle wm_concat()函数
    字符串拼接
    easyui扩展数据表格点击加号拓展
    子tab里面新增tab(top.jQuery)
    combox datagrid重复请求问题
  • 原文地址:https://www.cnblogs.com/xujiangli/p/5997781.html
Copyright © 2020-2023  润新知