1

I have a react app without a backend that is using localhost. In a component, there is an onClick handler which calls an external API to get data. The state is amended to have a piece of state be the return value of the API.

The code for that call:

fetch(statsURL)
    .then(function(response) {
        return response.resultSets.rowSet
    })

This generates the following error: enter image description here

In the Network details, I do get a 200 OK status code, and here is the header info: enter image description here

Let me know if you have any suggestions. Thanks

Kalamarico
  • 5,466
  • 22
  • 53
  • 70
jsc42
  • 117
  • 9

1 Answers1

0

You can use YQL to request resources that are not served with CORS headers. To get the response from a fetch() call use Response.text(), Response.json(), Response.blob() or Response.arrayBuffer()

fetch(statsURL)
.then(function(response) {
  return response.json()
})
.then(function(data) {
  console.log(data.resultSets.rowSet)
})
.catch(function(err) {
  console.error(err)
})
guest271314
  • 1
  • 15
  • 104
  • 177