我正在尝试从服务器获取一些数据,我使用的是react.js和fetch api
SyntaxError: Unexpected token < in JSON at position 0
这是我用来获取数据的代码
componentDidMount() {
// fetch all categories from the server
fetch('http:localhost:5555/categories')
.then(res => res.json())
.then(categories => {
this.setState({ loading: false });
console.log(categories);
this.setState({ categories });
})
.catch(err => {
this.setState({ loading: false });
console.log(err);
});
}
有什么想法吗?
发布于 2018-05-31 08:14:22
我认为问题出在您的fetch方法中,并且您编写的 url 的格式不正确,试图将url从
http:localhost:5555/categories
至
http://localhost:5555/categories
是否再次尝试获取
https://stackoverflow.com/questions/50614956
复制相似问题