运行 使用 create-react-app 对目录的 GET 请求

Run a GET request to directory using create-react-app

我在 create-react-app 项目上创建登录功能,但我不确定构建文件的目录结构如何工作...当 运行收到我收到的请求时404 错误。

我在 createUser.js

中有一个函数
componentDidMount() {
    this.serverRequest = $.get("./RestAPI/UserCRUD/create.php", function(users) {
        this.setState({
            users: users.records
        });
    }.bind(this));
}

理想情况下 运行 我编写的访问数据库的 php 脚本。我的问题是如何找到 URL 我需要在获取请求中指定以在 build 文件夹中调用此文件?

我假设 RestAPI 是您的 php 项目目录名称

所以如果你想从 reactjs 调用 rest api 你应该声明完整的 url 其余 api 就像

componentDidMount() {
    this.serverRequest = $.get("http://localhost/RestAPI/UserCRUD/create.php", function(users) {
        this.setState({
            users: users.records
        });
    }.bind(this));
}

希望对您有所帮助!!