API数据返回错误

时间:2017-01-08 22:45:22

标签: json api reactjs superagent

我正在使用superagent将api数据返回到控制台,但我遇到了这两个错误enter image description here

这是我正在使用的代码:

componentDidMount () {
    console.log("Did mount");

        const url = 'https://api.goodzer.com/products/v0.1/search_stores/?query=v-neck+sweater&lat=40.7575285&lng=-73.9884469&radius=5&priceRange=30:120&apiKey=0816b72b7c798c6c6994c915b0a1854d';
        superagent
        .get(url)
        .query(null)
        .set('Accept', 'text/json')
        .end((error, response) => {
          console.log(JSON.stringify(response.body));
        })   
      }

为什么我会收到这些错误?

1 个答案:

答案 0 :(得分:0)

我看到有两种方法可以解决这个问题:

<强> 1。使用服务器

在服务器上发出api.goodzer.com请求,然后向浏览器提供结果。我认为这可能是最好的解决方案,但如果您无法访问服务器,则可以使用选项2.

<强> 2。使用iframe

发出api.goodzer.com请求。这样,请求就会在自己的空间中发生。