我有一个像这样的对象:
$scope.user = {name: "Jim", birthday: "1/1/90", address: "123 Easy St"}
我正在对我的服务器进行$ http调用,我想传递这个用户信息。我这样想:
$http({
url: '/api/coolLookup/' + userID,
method: "GET",
params: {user:$scope.user}
}).success(function(data){
// do stuff
});
在我的服务器资源中(我在这里使用ExpressJS
/ Node
)我正在尝试访问user
对象但不能:
exports.coolLookup = function (req, res) {
console.log("Here's the user")
console.log(req.params.user)
}
req.params.user
在我的控制台中返回undefined。知道该怎么做吗?
答案 0 :(得分:1)
在Express中你应该这样做:
console.log(req.query.user);
(注意:query
,而不是params
)
这将为您提供一个字符串,使用JSON.parse()
将其转换为对象。