首页 > 代码库 > Ajax方法自定义重写

Ajax方法自定义重写

(function($) {
  var ajax = $.ajax;
  $.ajax = function(s) {
   var old=s.error;
   var old1 = s.success;
   s.error = function(xhr, status, err) {

    //可加上自己的判断处理
    var flag = xhr.getResponseHeader("noPermissions");
    if(flag != null && flag != ""){
     var result = xhr.responseText;
              var data = http://www.mamicode.com/eval("(" + result + ")");
     alert(data.msg);
     window.location.href = http://www.mamicode.com/data.url;
    }else{
     old(xhr,status,err); 
    }
   };
   s.success = function(data, textStatus, xhr){


   //可加上自己的判断处理    var flag = xhr.getResponseHeader("noPermissions");
    if(flag != null && flag != ""){
     var result = xhr.responseText;
              var data = http://www.mamicode.com/eval("(" + result + ")");
     alert(data.msg);
     window.location.href = http://www.mamicode.com/data.url;
    }else{
     old1(data, textStatus, xhr);
    }
   };
   ajax(s);
  }
 })(jQuery);

Ajax方法自定义重写