[英]fetch api change POST request to GET request when send it to the server
[英]failed to send a get request using fetch api
我正在尝试从服务器获取一些数据,并且正在使用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);
});
}
有什么想法吗
我认为问题出在您的提取方法中,并且您以错误的形式写入了网址 ,尝试从以下网址更改网址
http:localhost:5555/categories
至
http://localhost:5555/categories
任何尝试再次获取
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.