参考:https://blog.csdn.net/qq_41725450/article/details/83086423
https://blog.csdn.net/weixin_39706415/article/details/83652213
function network(){
$.ajax({
headers: {
"Authorization":localStorage.getItem("mytoken")//此处放置请求到的用户token
},
url:get_menu_url,
type: "get",
contentType: "application/json",
dataType: 'json',
cache: false,
async: true,
// beforeSend: function (XMLHttpRequest) {
// XMLHttpRequest.setRequestHeader("Authorization", localStorage.getItem("mytoken"));
// },
success: function(res) {
console.log("请求结果=="+JSON.stringify(res));
},
error:function() {
alert("请求失败!");
}
});
}
第二种:
function updateType(type) {
$.ajax({
url: mainUrl + "/order/updateType/" + localStorage.orderIds + "/" + type,
type: "post",
contentType: "application/json",
dataType: 'json',
cache: false,
async: true,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("token", localStorage.token);
},
success: function (result) {
if (result.status === 0) {
window.location.href = "my-order.html";
} else {
alert(result.msg)
}
}
});
}