[英]failed to send a get request using fetch api
I am trying to fetch some data from the server and I am using react.js and the fetch api but a get that 我正在尝试从服务器获取一些数据,并且正在使用react.js和fetch api,但是
SyntaxError: Unexpected token < in JSON at position 0
this is my code for fetching the data 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);
});
}
any thoughts 有什么想法吗
I think the problem is in your fetch method and you write the url in the wrong form try to change the url from 我认为问题出在您的提取方法中,并且您以错误的形式写入了网址 ,尝试从以下网址更改网址
http:localhost:5555/categories
to 至
http://localhost:5555/categories
any try to fetch again 任何尝试再次获取
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.