我正在POST
使用fetch
API从我的前端发出请求。但是当我在 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);
}
};