I am trying to fetch some data from the server and I am using react.js and the fetch api but a get that
SyntaxError: Unexpected token < in JSON at position 0
this is my code for fetching the data
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