重写ajax方法
我想重写ajax方法,想在重写方法里统一处理权限和异常,百度了一圈,也封装了,但是发现个问题,没封装前的方法可以设置headers,但是封装后就不识别了,有没有大神指点一下,想要封装ajax方法,header怎么处理
重写的如下
(function($){
//首先备份下jquery的ajax方法
var _ajax=$.ajax;
//重写jquery的ajax方法
$.ajax = function (opt) {
//备份opt中error和success方法
opt.type = 'POST';
opt.cache = false;
alert( opt.headers)
var fn = {
error:function(XMLHttpRequest, textStatus, errorThrown){},
success:function(data, textStatus){}
}
if(opt.error){
fn.error=opt.error;
}
if(opt.success){
fn.success=opt.success;
}
。。。。。。
没封装的时候
$.ajax({
headers: headers,
url: url,
data: {
userid: userid,
lockstate: lockstate
},
。。。。。。
这个headers怎么办,里面是token