$.ajaxSetup({
contentType: "application/x-www-form-urlencoded;charset=utf-8",
//请求发送之前
beforeSend: function (xhr) {
console.log("false");
xhr.setRequestHeader("Authorization", "Token 123");
},
//请求完成之后
complete: function (XMLHttpRequest, textStatus) {
console.log("true");
//通过XMLHttpRequest取得响应头,sessionstatus,
var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
if (sessionstatus == "timeout") {
//如果超时就处理 ,指定要跳转的页面(比如登陆页)
window.location.replace("/login/index.php");
}
},
});