首页 > 解决方案 > 这两个调用有什么区别?

问题描述

我一生都无法弄清楚发生了什么。

我有这两个电话,这个工作并准确记录了我的期望。

getEmployeeId() {
    fetch(API_URL + `/clients/all`)
      .then((res) => {
        if (!res.ok) {
          throw new Error();
        }
        return res.json();
      })
      .then((result) => {
        console.log(result);
      });
  }

这一个,记录一个空数组。获取路径的唯一区别。

getEmployeeId() {
    fetch(API_URL + `/interviews/getEmployeeId`)
      .then((res) => {
        if (!res.ok) {
          throw new Error();
        }
        return res.json();
      })
      .then((result) => {
        console.log(result);
      });
  }

这当然让我认为问题一定出在 API 路由中。这个有效:

app.get('/clients/all', function (req, res) {
    connection.getConnection(function (err, connection) {
        connection.query("SELECT * FROM clients", function (error, results) {
            // If some error occurs, we throw an error.
            if (error) throw error;
            console.log(results);
            res.json(results);
        });
        connection.release();
    });
});

这个没有:

app.get("/interviews/getEmployeeId", function (req, res) {
  connection.getConnection(function (err, connection) {
    connection.query("SELECT * FROM audit_interview", function (error, results) {
      if (error) throw error;
      console.log(results);
      res.json(results);
    });
    connection.release();
  });
});

对它们的查询调用在 mySql Workbench 中按预期工作。有人发现问题吗?

标签: javascriptmysqlreactjs

解决方案


推荐阅读