未定义从node.js参数中的GET请求获取数据 [英] Get data from GET request in node.js parameters undefined
问题描述
我试图从Node.js中通过Angular.JS获取请求中的参数,但在输出中获取未定义的数据
$ b
http:// localhost:3000 / admin / dashboard?id = 582c5211c8a8e06c0849a238
我的CRUD是
dashboard:{
schema:DashboardSchema,
custom:[{
type:after,
request:get,
controller:dashboardController.dashboard
}]
}
我的Node.js代码是
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'}
here
{id:undefined}
undefined
请帮助!
http:// localhost:3000 / admin / dashboard?id = 582c5211c8a8e06c0849a238
在您传递查询时,请尝试
req.query.id
如果您将参数传递为
http:// localhost:3000 / admin / dashboard / 582c5211c8a8e06c0849a2
然后您可以使用req.params.id
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=582c5211c8a8e06c0849a238
My CRUD is
"dashboard":{
schema:DashboardSchema,
custom:[{
type:"after",
request: "get",
controller: dashboardController.dashboard
}]
}
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"});
});
The console window shows like this
GET /admin/dashboard?id=582c5211c8a8e06c0849a238 200 153.463 ms - 14 In decode data { id: '582c5211c8a8e06c0849a238' } here { id: undefined } undefined
Please help !
http://localhost:3000/admin/dashboard?id=582c5211c8a8e06c0849a238
Here as you are passing in query so try req.query.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屋!