私は$.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
コールバック関数を渡そうとしていますが、個々の呼び出しからそれを行う方法がわかりません。誰にもアイデアがありますか?