【发布时间】:2021-08-17 19:31:46
【问题描述】:
我正在尝试发出 POST 请求并打印响应。我的代码:
async function create_invite(){
console.log("creating.....")
const response = await fetch('https://localhost:8080/webhooks', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload)
}).catch(error => console.log(error))
console.log(response.json())
}
document.getElementById('create_invite').addEventListener("click", create_invite)
但我得到了这个错误
Uncaught (in promise) TypeError: response is undefined
我尝试在标题中添加 cors 但仍然不起作用
【问题讨论】:
-
你必须点击返回
undefined的.catch
标签: javascript api fetch-api