JS实现ajax请求头添加token,如何实现呢?直接上DEMO。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)
}
}
});
}