node.js - req.params.id 未定义,ReferencesError : id 未定义
问题描述
这是浏览器中的网址
http://localhost:8888/update/1
这是路线的代码
router.addRoute("/update/:id", (req, res) => {
conn.query(
"select * from mahasiswa where ? ",
{ no_induk: req.params.id },
function (err, rows, field) {
if (rows.length) {
if (req.method.toUpperCase() == "POST") {
} else {
let html = view.compileFile("./tamplate/form_update.html")();
res.writeHead(200, { "Contact-Type": "text/html" });
res.end(html);
}
} else {
let html = view.compileFile("./tamplate/form_update.html")();
res.writeHead(200, { "Contact-Type": "text/html" });
res.end(html);
}
}
);
});
请帮帮我我不知道
解决方案
我认为最好使用 router.post
例如:
router.post("/update/:id", (req, res) => {
conn.query(
"select * from mahasiswa where ? ",
{ no_induk: req.params.id },
function (err, rows, field) {
if (rows.length) {
let html = view.compileFile("./tamplate/form_update.html")();
res.writeHead(200, { "Contact-Type": "text/html" });
res.end(html);
}
}
});
推荐阅读
- sql - 比较在不同时间更新的同一唯一项目的同一列中的值
- flutter - FutureBuilder 显示 AlertDialog - 将焦点放在 TextField 时,所有者小部件会重建
- c - 在 C 中打印这种特定三角形图案的最佳方式/方法是什么?
- c# - 是否可以在 Xamarin 项目中使用已经创建的 Sqlite 数据库?
- python - 使用 python-pep8 出错
- r - 每次运行代码时,是否可以使用特定功能来分配不同的名称?
- snakemake - snakemake “rule all” 正在重新运行不必要的规则
- android - 在可见性可见后如何对recyclerview进行ui测试
- python - Selenium 信用卡模块元素不可交互
- windows - 视窗。文件权限在从一个 NTFS 磁盘复制到另一个 NTFS 磁盘期间更改