首页 > 解决方案 > “尝试获取资源时出现网络错误。” 仅在火狐上

问题描述

我正在使用APIPOST从我的前端发出请求。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);
        }
  };

标签: javascriptreactjsfirefoxfetchnext.js

解决方案


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


推荐阅读