我正在POST使用 API 从前端发出请求fetch。但当我在 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);
}
};
Run Code Online (Sandbox Code Playgroud) 所以,我想向我的网站添加一个 ads.js,但是 Next github 中的示例不太清楚。有人知道该怎么做吗?这是带有机器人和站点地图的下一个示例: https://github.com/zeit/next.js/tree/canary/examples/with-sitemap-and-robots-express-server
谢谢你!