【发布时间】:2016-05-10 13:49:39
【问题描述】:
我正在传递一个包含“葡萄酒”数组的 POST。发送上的对象看起来行。但是,当我在服务器端记录请求时,数组是键和值的集合。我错过了什么:
**** 我的测试请求代码****
request.post("http://localhost:3000/todos", {form: params}, function(err, response){
console.log(response.body);
})
**** 正在发送的选项****
var params = {
name: 'Test Do',
summary: 'This is the summary',
wines: ['56ad66897070ffc5387352dc', '56dg66898180ffd6487353ef']
}
**** 我的服务器端代码 --- 为简洁起见缩短 ***
exports.todoPost = function(req, res){
console.log(req.body);
var todo = new ToDo(req.body);
todo.save(function(err, todoX){
if(err){return res.send.err;}
console.log(req.body.store_config)
if(todo.wines){
**** 'console.log(req.body) **** 的输出
{ name: 'Test Do',
summary: 'This is the summary',
'wines[0]': '56ad66897070ffc5387352dc',
'wines[1]': '56dg66898180ffd6487353ef' }
我不能在 POST 中发送数组吗?我在网上看到的一切以及我尝试过的一切都不起作用。它说我正确地传递了东西。
【问题讨论】:
标签: javascript arrays node.js request javascript-objects