1

I'm tryng to get a list of data from another website, but i keep getting the error:

dataFetcher.ts:7 Uncaught (in promise) SyntaxError: Unexpected end of input

this is the code I am using:

return await fetch('http://otherwebsite.com/export/export.json',  { mode: 'no-cors' } )
    .then((res) => res.json());

What am I missing? (when I inspect the data im retrieving everything looks normal)

BittyBoop
  • 15
  • 4
  • Try this link https://stackoverflow.com/questions/43262121/trying-to-use-fetch-and-pass-in-mode-no-cors – Varun Sharma Jun 21 '20 at 12:16
  • I see you have `{mode: 'no-cors' }` in your options - if this is in fact a `CORS` issue, you won't be able to do to anything about it. – goto Jun 21 '20 at 12:19
  • Remove the mode options and pass the proxy url before your mentioned url. As mentioned in this link :- https://stackoverflow.com/questions/43262121/trying-to-use-fetch-and-pass-in-mode-no-cors – Varun Sharma Jun 21 '20 at 12:31
  • thanks that did solve the problem. but why do I need a proxy if the data is public? – BittyBoop Jun 21 '20 at 14:12
  • `CORS` has nothing to do with whether the data is public or not - read about `CORS` here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS – goto Jun 21 '20 at 18:57

1 Answers1

0

A request with mode: no-cors returns a opaque response, which is not readable.

See here: Trying to use fetch and pass in mode: no-cors

korki
  • 163
  • 7