Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法使用fetch api发送get请求_Javascript_Reactjs - Fatal编程技术网

Javascript 无法使用fetch api发送get请求

Javascript 无法使用fetch api发送get请求,javascript,reactjs,Javascript,Reactjs,我正在尝试从服务器获取一些数据,我正在使用react.js 而fetchapi只是一个get SyntaxError:JSON中位置0处的意外标记

我正在尝试从服务器获取一些数据,我正在使用react.js 而fetchapi只是一个get

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