【发布时间】:2019-09-20 02:21:52
【问题描述】:
我有这段代码,它在页面加载时按预期工作,但是当我在选中复选框后尝试进行调用时,它会显示请求标头字段 x-csrf-token 不允许 Access-Control-Allow-预检响应中的标头。
$.ajax
({
type: 'POST',
url: "https:/www.bb.com?uId=123&mId=123",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", "Basic dTHIgdfgsjdhgfsgfjhsfghsfkjs879"); },
dataType: 'json',
success: function (data) {
console.log(data);
},
error: function (xhr, status, error) {
console.log(xhr);
console.log(status);
console.log(error);
}
});
and for checking:
$("input:checkbox[name=list]").click(function () {
if ($(this).is(':checked')) {
do that call
}
});
任何想法如何鞋底?
【问题讨论】:
-
更改
Access-Control-Allow-Headers以允许它......或者不发送令牌(您共享的代码不是设置) -
我无法控制服务器代码
标签: javascript ajax cors