从 node.js 参数中的 GET 请求获取数据未定义 [英] Get data from GET request in node.js parameters undefined

查看:51
本文介绍了从 node.js 参数中的 GET 请求获取数据未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过 Angular.JS 从 Node.js 中的 get 请求获取参数,但在输出中未定义

I am trying to get parameters from get request in Node.js through Angular.JS but getting undefined in output

http://localhost:3000/admin/dashboard?id=582c5211c8a8e06c08849a

http://localhost:3000/admin/dashboard?id=582c5211c8a8e06c0849a238

我的 CRUD 是

"dashboard":{
     schema:DashboardSchema,
     custom:[{
         type:"after",
         request: "get",
         controller: dashboardController.dashboard
     }]
}

我的 Node.js 代码是

My Node.js code is

dashboard: function(req,res){
     console.log("here");
     console.log(req.params);
     console.log(req.params.id);
     return res.status(200).send({"data":"123"});
});

控制台窗口显示如下

GET/admin/dashboard?id=582c5211c8a8e06c0849a238 200 153.463 ms - 14在解码数据 { id: '582c5211c8a8e06c0849a238' }这里{ id: 未定义 }未定义

GET /admin/dashboard?id=582c5211c8a8e06c0849a238 200 153.463 ms - 14 In decode data { id: '582c5211c8a8e06c0849a238' } here { id: undefined } undefined

请帮忙!

推荐答案

http://localhost:3000/admin/dashboard?id=582c5211c8a8e06c0849a238

在这里,当您传入查询时,请尝试req.query.id

Here as you are passing in query so try req.query.id

如果您将参数传递为http://localhost:3000/admin/dashboard/582c5211c8a8e06c0849a238然后你可以使用 req.params.id

If you are passing the parameters as http://localhost:3000/admin/dashboard/582c5211c8a8e06c0849a238 then you can use req.params.id

这篇关于从 node.js 参数中的 GET 请求获取数据未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆