“尝试获取资源时出现网络错误。” 仅在火狐浏览器上

Taí*_*tas 4 javascript firefox reactjs fetch-api next.js

我正在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)

kro*_*oiz 6

对我来说,这是添加 event.preventDefault() 的问题