Javascript 无法使用fetch api发送get请求
我正在尝试从服务器获取一些数据,我正在使用react.js 而fetchapi只是一个getJavascript 无法使用fetch api发送get请求,javascript,reactjs,Javascript,Reactjs,我正在尝试从服务器获取一些数据,我正在使用react.js 而fetchapi只是一个get SyntaxError:JSON中位置0处的意外标记
SyntaxError:JSON中位置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);
});
}
任何想法我认为问题在于您的获取方法,您以错误的形式编写了url 尝试从更改url
http:localhost:5555/categories
到
有人想再去拿吗
http://localhost:5555/categories