[英]Fetch no-cors Unexpected end of input
Using react and webpack.. why does the code below result in an error: Uncaught (in promise) SyntaxError: Unexpected end of input(…)
? 使用react和webpack ..为什么下面的代码会导致错误:
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));
To better understand your error, add a catch case to your fetch request. 为了更好地理解您的错误,请在抓取请求中添加一个catch案例。
Also, if you use arrow functions, you don't need to bind(this); 另外,如果使用箭头函数,则不需要绑定(this);
fetch(feedURL, {"mode": "no-cors"})
.then(response => response.json())
.then(data => {
this.setState({
data: data
});
})
.catch(resp => {
console.error(resp);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.