jquery的ajax全局配置

来源:互联网 发布:关于网络婚恋案例 编辑:程序博客网 时间:2024/05/23 01:16

 jquery的ajax全局配置

var token = localStorage.getItem("token");$.ajaxSetup({    dataType: "json",    cache: false,    headers: {        "token": token    },    xhrFields: {        withCredentials: true    },    complete: function(xhr) {        //token过期,则跳转到登录页面        if(xhr.responseJSON.code == 401){            parent.location.href = baseURL + 'login.html';        }    }});

jqgrid全局配置

var token = localStorage.getItem("token");$.extend($.jgrid.defaults, {    ajaxGridOptions : {        headers: {            "token": token        }    }});