【发布时间】:2021-08-24 04:47:22
【问题描述】:
我尝试将它作为 jquery ajax 发布它可以正常工作。
数据将被硬编码,但代码是一个动态值。
const data = {
"retrieve": {
"header": {
"userID": 'xxx',
},
"body": {
"code": code,
"channel" : []
}
}
}
我用web fetch api发帖,失败了。
const response = await fetch('https://api', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
const result = await response.json();
工作如果我使用 $.ajax
const response = await $.ajax({
method: 'POST',
url: 'https://api',
data: JSON.stringify(data),
contentType: 'application/json'
})
【问题讨论】:
-
当你说原生的
fetch()不行的时候,是什么坏了?你的网络标签说什么?您的浏览器控制台中是否有任何错误?