【发布时间】:2015-03-11 04:45:51
【问题描述】:
我想发送我的server.js(在 AngularJS 控制器中)设置 id 参数,如下所示:
$http
.get('/getCst', {
params: {
id: customerID
}
})
.success(function (data,status) {
$scope.customer = data
});
但我不确定这是否是正确的方法以及在 Node.js server.js 中写什么:
app.get('/getCst', function (req, res) {
console.log(//how do i get the id sent by the client?);
});
【问题讨论】:
-
它不是重复的。我的 url 看起来像
127.0.0.1:8080/cust/534543534543 是 id。我不能用 req.query.id 得到它 -
/cust/534543和/getCst有什么关系?您的 AngularJS 代码不会向/cust/534543发出 GET 请求,而不是向/getCst/534524发出 GET 请求。它将调用/getCst?id=534534。 docs.angularjs.org/api/ng/service/$http -
使用
req.query.id。参考:stackoverflow.com/questions/17007997/…