javascript - “尝试获取资源时出现网络错误。” 仅在火狐上
问题描述
我正在使用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);
}
};
解决方案
对我来说,这是添加 event.preventDefault() 的问题
推荐阅读
- android - RxAndroid,如何仅订阅此响应的“数据”数组?
- dynamics-crm - Dynamics 365 CRM 门户。缺少富文本编辑器
- symfony4 - Modernizr 插件和 webpack 安可
- kubernetes - Kubernetes 中的有状态作业
- android - 可以对大数据对象使用共享首选项吗?
- html - 如何在不影响其他 div 元素位置的情况下覆盖 div
- java - 我无法使用休眠本地会话工厂对象更新特定行的“shop_table”表值?
- c# - 视频和aufio文件的实际时长
- node.js - AWS Custom Authorizer 不工作,返回请求超时
- python - 在python中使用re模块时,使用\S$匹配得到的结果会丢失字符串中的最后一个元素