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