2

I have a problem with flickr public API, this code:

fetch('https://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&per_page=9&tags=Porsche', {
  headers: {
    'Accept'        : 'application/json',
    'Content-Type'  : 'application/json'
  },
  mode: 'no-cors',
})
.then(data => {
  return data.json();
})

returns Unexpected end of input in the browser console. What is wrong with this code?

dakolech
  • 522
  • 4
  • 17
  • What is the output are you expecting in the then callback? – siva Apr 17 '17 at 15:21
  • 1
    When I paste it into the browser, I'm getting a json with proper data. Also when I run this code in the console, I can see in the network tab, that the request and response are correct, but the code fails. – dakolech Apr 17 '17 at 15:24
  • 2
    Looks like you can't access `no-cors` request responses via JavaScript: http://stackoverflow.com/questions/36292537/what-is-an-opaque-request-and-what-it-serves-for | also http://stackoverflow.com/questions/39109789/what-limitations-apply-to-opaque-responses – yuriy636 Apr 17 '17 at 15:29
  • 1
    Since you have used the no-cors mode your response will be opaque type. you can see that when print the response in console. can you check this link why the code fails. http://stackoverflow.com/questions/36840396/react-fetch-gives-an-empty-response-body – siva Apr 17 '17 at 15:37

0 Answers0