我正在使用这些代码来设置ajax设置的授权标头,但它不能正常工作
$.ajaxSetup({
beforeSend: function(xhr, options) {
var encoded_auth_token, header;
if (Remon.Auth.get('auth_token')) {
console.log("there is a request");//triggered
encoded_auth_token = Base64.encode64(Remon.Auth.get('auth_token') + ":X");
header = "Basic " + encoded_auth_token;
xhr.setRequestHeader("Authorization", header);
return true;
}
},
error: function(xhr) {
if (xhr.status === 401) {
console.log("unauth");
}
if (xhr.status === 404) {
console.log("wrong");
}
}
});
没有设置请求标头我已经包含了Base64,还有Remon.get(“auth_token”)正在工作,并且触发了console.log