【问题标题】:Call get API with params使用参数调用 get API
【发布时间】: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

标签: node.js api get


【解决方案1】:

随便用

window.location.replace('/bill/edit/id='+id);

这对我有用。我希望它也可以帮助你。

【讨论】:

    猜你喜欢
    • 2013-10-17
    • 1970-01-01
    • 1970-01-01
    • 2012-08-12
    • 2023-03-10
    • 1970-01-01
    • 2017-09-25
    • 2017-06-05
    • 2011-12-16
    相关资源
    最近更新 更多