$.ajaxSetup({
beforeSend: function(request) {
var nonce = Date.parse(new Date());
var appid = "PCA87hh7I8uu0ncs";
var secret = "reL4tVMjA3HdFjsTkqnUmmZpBbqKgq";
var Accept = "application/vnd.dtoa.v14+json";
var url = localStorage.getItem("api_url");
var user_token = localStorage.getItem("user_token");
var Authorization = hex_md5(appid + "&" + secret + "&" + user_token + "&/" + url);
console.log(user_token);
var Authorization_java = hex_md5(user_token + nonce + url);
Authorization = "Bearer " + user_token + "." + Authorization;
request.setRequestHeader("nonce", nonce);
request.setRequestHeader("Accept", Accept);
request.setRequestHeader("user_token", user_token);
request.setRequestHeader("Authorization", Authorization);
request.setRequestHeader("Authorization_java", Authorization_java);
request.setRequestHeader("APPID", appid);
request.setRequestHeader("secret", secret);
request.setRequestHeader("Client", "Pc");
showLoading();
if(user_token == null) {
logoOut();
$(".paster-con-container").remove()
}
},
complete: function() {
closeLoading();
},
error: function(data) {
var data = data;
console.log(data);
if(data) {
if(data.responseJSON) {
if(data.responseJSON.status_code == 401) {
if(!isAlert) {
isAlert = true;
alert(data.responseJSON.message);
logoOut();
$(".paster-con-container").remove()
}
} else {
alert(data.responseJSON.message);
}
} else {
console.log(JSON.stringify(data));
}
}
}
});
$.ajaxSetup({
beforeSend:function(request){
var nonce = Date.parse(new Date());
var Accept = "application/vnd.dtoa.v14+json";
var url = "api/adviser/adviserGroups";
var user_token = "4503776648acdfb9812ac8ad70990edc";
var Authorization_java = hex_md5(user_token + nonce + url);
request.setRequestHeader("nonce", nonce);
request.setRequestHeader("Accept", Accept);
request.setRequestHeader("user_token", user_token);
request.setRequestHeader("Authorization_java", Authorization_java);
request.setRequestHeader("APPID","PCA87hh7I8uu0ncs");
request.setRequestHeader("secret","reL4tVMjA3HdFjsTkqnUmmZpBbqKgq");
console.log(Authorization_java);
},
error:function(data){
console.log(JSON.stringify(data));
}
});
$.ajaxSetup ---- ajaxSetup() 方法为将来的 AJAX 请求设置默认值
语法:$.ajaxSetup({name:value, name:value, ... })
参数:
async | 布尔值,表示请求是否异步处理。默认是 true。 |
beforeSend(xhr) | 发送请求前运行的函数。可设置请求头 |