Fetch no-cors unexpected input end

Using reaction and webpack .. why does the code below lead to an error: Uncaught (in promise) SyntaxError: Unexpected end of input(…) ? Thanks

  fetch(feedURL, {"mode": "no-cors"}) .then(response => response.json()) .then(function(data){ this.setState({ data: data }) }.bind(this)); 
+7
javascript reactjs
source share
1 answer

To better understand your mistake, add a catch case to your fetch request.

Also, if you use arrow functions, you do not need to bind (this);

 fetch(feedURL, {"mode": "no-cors"}) .then(response => response.json()) .then(data => { this.setState({ data: data }); }) .catch(resp => { console.error(resp); }); 
0
source share

All Articles