【发布时间】:2020-03-29 06:48:17
【问题描述】:
我正在使用fetch API 从我的前端发出POST 请求。但是当我在 Firefox 中尝试时,它不起作用。在 Chrome 中工作正常。
这就是我想要做的。
const handleSubmit = async event => {
try {
await fetch(`https://api.example.net/api/route?slug=example`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
'x-api-key': /* API KEY*/
},
body: JSON.stringify({
name,
email
})
})
.then(response => console.log(response))
.catch(err => console.log(err));
} catch (error) {
console.log(error);
}
};
【问题讨论】:
标签: javascript reactjs firefox fetch next.js