javascript - 这两个调用有什么区别?
问题描述
我一生都无法弄清楚发生了什么。
我有这两个电话,这个工作并准确记录了我的期望。
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 中按预期工作。有人发现问题吗?
解决方案
推荐阅读
- reactjs - React Query 或 Apollo Client 如何确保更新数据?
- c - “struct variable”类型的参数与“const char *”类型的参数不兼容
- c - 当我向它添加元素时,根节点会丢失吗?
- python - 为什么字符串格式比在 Python 中将某些内容转换为字符串要快得多?
- regex - 匹配 perl 正则表达式中括号和方括号之外的所有逗号
- python - 如何解决 Anaconda Prompt 中的 ModuleNotFoundError
- android - 从屏幕中删除导航抽屉
- android - 如何使 Android Studio 的编译忽略正常问题?
- reactjs - 如何有条件地比较 React 中的状态和值?
- json - 使用 Notepad++ 或任何其他方法查找文本并增加特定数量?