mainUrl是定义的全局的域名,localStorage.token是登录进来存储的token,这个token最好是放在session中,async表示异步
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)
}
}
});
}