Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 调用外部API时获取CORS/Origin错误_Javascript_Api_Reactjs - Fatal编程技术网

Javascript 调用外部API时获取CORS/Origin错误

Javascript 调用外部API时获取CORS/Origin错误,javascript,api,reactjs,Javascript,Api,Reactjs,我有一个react应用程序,没有使用localhost的后端。在组件中,有一个onClick处理程序,它调用一个外部API来获取数据。状态被修改为将一段状态作为API的返回值 该调用的代码: fetch(statsURL) .then(function(response) { return response.resultSets.rowSet }) 这将生成以下错误: 在网络详细信息中,我得到了一个200 OK状态代码,下面是标题信息: 如果你有任何建议,请

我有一个react应用程序,没有使用
localhost
的后端。在组件中,有一个
onClick
处理程序,它调用一个外部API来获取数据。状态被修改为将一段状态作为API的返回值

该调用的代码:

fetch(statsURL)
    .then(function(response) {
        return response.resultSets.rowSet
    })
这将生成以下错误:

在网络详细信息中,我得到了一个200 OK状态代码,下面是标题信息:

如果你有任何建议,请告诉我。谢谢

您可以使用它来请求未提供CORS头的资源。要从
fetch()
调用获取响应,请使用
response.text()
response.json()
response.blob()
response.arrayBuffer()

您可以使用来请求未提供CORS标头的资源。要从
fetch()
调用获取响应,请使用
response.text()
response.json()
response.blob()
response.arrayBuffer()


谢谢你的建议。不幸的是,我将这段代码添加到了我的文件中,但在控制台中仍然出现相同的错误。@jsc42您是否使用YQL请求资源?谢谢您的建议。不幸的是,我将此代码添加到了我的文件中,但在控制台中仍然会出现相同的错误。@jsc42您是否使用YQL请求资源?
fetch(statsURL)
.then(function(response) {
  return response.json()
})
.then(function(data) {
  console.log(data.resultSets.rowSet)
})
.catch(function(err) {
  console.error(err)
})