javascript - 跨域请求被阻止:同源策略不允许读取位于 ... 的远程资源:CORS 标头“Access-Control-Allow-Origin”缺失
问题描述
我正在尝试在 React 中使用 axios 从在线 JSON 文件中获取数据,起初它工作正常,但突然间我在磁贴中得到错误。我没有改变任何东西,但突然我得到了错误。我无权访问服务器。我刚刚做了 create-react-app 并且我在前端工作。
在 App.js 中:
componentDidMount() {
axios.get(' url is here ') //not sure if im allowed to share the url, but I did put the url of the json file here
.then(res => {
this.setState({ pageData : res.data, isLoading : false });
})
}
解决方案
推荐阅读
- amazon-web-services - 如何在 S3 中保存模型并在 Sagemaker 中保存检查点
- python - IndexError:numpy ndarray中的布尔索引与索引数组不匹配
- python-3.x - 如何将 JSON 数据转换为 Python 对象并在表格中显示
- database - 将所有值从 CSV 插入到其他表引用的 Postgres 表的正确方法是什么?
- javascript - 为什么茉莉花不运行测试?
- typescript - 为什么 Typescript 不尊重返回对象的接口中的类型?
- reactjs - 为什么反应把我的状态变成[对象对象]
- spring - 使用 Spring Boot 配置 MongoDB?
- google-cloud-platform - 当我将域 (Google Domains) 更改为指向 GCP 名称服务器时,Gsuite 电子邮件无法与 Google Cloud Platform 一起使用
- javascript - 设置已删除的事件 ID