全局添加token
var token = sessionStorage.getItem("UserTocken"); if(token){ $.ajaxSetup({ //发送请求前触发 beforeSend: function(xhr) { //可以设置自定义标头 xhr.setRequestHeader('Authorization', "Bearer " + token); } }) }else{ var host_url = window.location.host; window.location.replace("http://" + host_url); }