为什么Express.js不能正确读取POST参数?

时间:2012-05-06 23:09:40

标签: node.js http-post express

是我的帖子:

account_id  1231
limit   3
ordertype   limit
quantity    1
symbol  USDJPY
transaction_type    buy

在我的代码中,我有:

 var account_id = req.param('account_id', null);
  var symbol_pair = req.param('symbol', null);
  var transaction_type = req.param('transaction_type', null);
  var order_type = req.param('ordertype', null);
  var amount = req.param('amount', null);
  var limit = req.param('limit', null);

console.log(account_id + " | " + symbol_pair + " | " + transaction_type + " | " + order_type + " | " + amount + " | " + limit);return;

但出于某种原因,ordertype会回来market。有什么想法正在发生什么?

2 个答案:

答案 0 :(得分:3)

确保您拥有app.use(express.bodyParser());并尝试使用req.body.account_id(并为每个人尝试类似的风格)

http://expressjs.com/guide.html#http-methods

答案 1 :(得分:0)

您正在定义order_type,然后尝试使用ordertype将其恢复。别忘了你的下划线!