我$.ajaxSetup
习惯于在我的站点中使用全局授权方法和全局错误处理。我想将一个回调函数传递给全局错误方法,这样我就可以在需要时在全局错误处理程序中调用该函数。这是我的$.ajaxSetup
:
$.ajaxSetup({
global: false,
// type: "POST",
beforeSend: function (xhr) {
//The string needs to be turned into 'this.pasToken'
//if not us, don't include
if(app.cookieAuth)
xhr.setRequestHeader("Authorization", _this.pasToken);
},
statusCode: {
401: function(){
//Redirect to the login window if the user is unauthorized
window.location.href = app.loginUrl;
},
//This is where I need help
403: function(error, callback){
//Show an error message if permission isn't granted
callback(error);
alert(JSON.parse(error.responseText)['Message']);
}
}
});
注意403:
状态码。我正在尝试传入一个回调函数,但我不知道如何从各个ajax
调用中做到这一点。有人有想法吗?