获取no-cors意外的输入结束

时间:2016-06-23 18:51:48

标签: javascript reactjs

使用react和webpack ..为什么下面的代码会导致错误:Uncaught (in promise) SyntaxError: Unexpected end of input(…)?感谢

    fetch(feedURL, {"mode": "no-cors"})
    .then(response => response.json())
    .then(function(data){

        this.setState({
            data: data
        })

    }.bind(this));

1 个答案:

答案 0 :(得分:0)

为了更好地理解您的错误,请在抓取请求中添加一个catch案例。

此外,如果使用箭头功能,则无需绑定(this);

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