首页 > 解决方案 > 跨域请求被阻止:同源策略不允许读取位于 ... 的远程资源: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 });
      })
  }

标签: javascriptjsonreactjsapiaxios

解决方案


推荐阅读