[英]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.