使用"ajax post“的系统在我使用"fetch post”时无法工作。
我已经处理这个问题好几天了,非常感谢,如果有人能帮上忙的话。
var json_data = {};
json_data.saveitem = JSON.stringify(OtherJson);
$.ajax({
url: url,
method: "post",
data: json_data,
async:false,
success: function (response) {
console.log(response);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});事务结束时返回的消息如下;
{"errno":0,"errdesc":"","success":true,"result":[]}这没什么,一切都很好,但是当我使用下面的方法执行时,"SyntaxError: JSON input的意外结束“给出了这个错误。在它所指向的行中有".catch“部分。
fetch(url, {
method: "POST",
body: json_data,
headers: {"Content-type": "application/json; charset=UTF-8"}
})
.then(res => res.json())
.then(res => {
console.log(res);
})
.catch(error => {
console.log(error);
});发布于 2021-02-20 22:36:20
headers: {"Content-type": "application/json; charset=UTF-8"}删除application/json旁边的;,并替换为,我想是这样吗?
https://stackoverflow.com/questions/66292632
复制相似问题