【发布时间】:2018-03-18 13:42:54
【问题描述】:
我是 node.js 的新手,我想调用 get API。情况是,我有一个编辑按钮,然后单击该按钮我想调用 API。
为此,我为调用 API 创建了一个函数。
function edit(id){
window.location.replace('/p/edit?id='+id);
}
在后端我已经将 API 设置为这样。
router.get('/edit/:id' , function(req , res , next){
console.log("API calling...");
});
在app.js文件中,
app.use('/p' , require('./routes/test'));
【问题讨论】:
-
你用的是快递吗?
-
是的,我正在使用 express,在 CMD 中我收到了消息
GET /bill/edit?id=1 404 31.480 ms - 786 -
获取 URL 参数的值,使用 req.params app.get('/p/:id', function(req, res) { res.send("tagId is set to " + req .params.id); });
-
我想在 url 中设置
edit?id=1所以我使用edit/:id -
当我使用邮递员调用 API 时,作为响应,我得到了堆栈跟踪。
<h1>Not Found</h1> <h2>404</h2> <pre>Error: Not Found at E:\gautum\app.js:30:13