我有一个我想传递给服务器的ID数组。我在网上看到的其他答案描述了如何在url中传递这些id作为查询参数。我不想使用这种方法,因为可能会有很多ID。这是我曾尝试:
AngularJS:
console.log('my ids = ' + JSON.stringify(ids)); // ["482944","335392","482593",...]
var data = $.param({
ids: ids
});
return $http({
url: 'controller/method',
method: "GET",
data: data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function (result, status, headers, config) {
return result;
})
的Node.js:
app.get('/controller/method', function(req, res) {
console.log('my ids = ' + JSON.stringify(req.body.ids)); // undefined
model.find({
'id_field': { $in: req.body.ids }
}, function(err, data){
console.log('ids from query = ' + JSON.stringify(data)); // undefined
return res.json(data);
});
});
为什么我在服务器端得到undefined
?我怀疑这是因为我使用了$.params
,但我不确定。
对于通过此方法发送的数据量有限制吗?我担心的是,如果我发送大量ID,它会中断。 – 2014-08-31 01:18:54