跨域,服務器已開放請求接口,用$post可以成功,但是無法添加header信息,用$ajax的話會把post信息換成OPTIONS發送請求,data跟header都無法發送出去,不知道有什么好的辦法可以解決~~
// $.post(Common.postUrl + '/wechat/register',
// JSON.stringify({
// phone: tel,
// publicId: getcookie().publicId,
// header: header,
// authCode: code,
// focusTime: Date.parse(new Date())
// }), function (data) {
// data = JSON.parse(data);
// if (data.status == 200) {
// alertBottom('登錄成功');
// setTimeout(function () {
// window.href = 'index.html';
// }, 2000)
// } else {
// alertBottom(returnMessage[data.status]);
// }
// });
$.ajax({
type: "POST",
url: Common.postUrl + '/wechat/register',
data:JSON.stringify({
phone: tel,
publicId: getcookie().publicId,
header: header,
authCode: code,
focusTime: Date.parse(new Date())
}),
contentType: "application/x-www-form-urlencoded",
headers:{
key:'Cookie'
},
processData: false,
beforeSend: function (xhr) {
xhr.setRequestHeader("key", "Cookie");
},
success: function (data) {
}
});
怎么給jquery跨域post請求添加頭部信息?
慕碼人8056858
2019-03-04 01:31:11