【问题标题】:Why won't Express.js properly read POST parameters? [closed]为什么 Express.js 不能正确读取 POST 参数? [关闭]
【发布时间】:2012-05-06 23:09:39
【问题描述】:

这是我的帖子:

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。有什么想法吗?

【问题讨论】:

  • 这样的问题很难回答。也许您忘记了下划线(order_type vs ordertype)?你可以通过 console.log( req.params ) 来查看你有哪些可用的参数。
  • 需要更多信息。您能否向我们展示实际执行 POST 的代码?请尝试@Pickels 记录req.params 的建议。

标签: node.js http-post express


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您正在定义 order_type,然后尝试使用 ordertype 将其取回。不要忘记你的:下划线!

    【讨论】:

    • 这不是真的,var 被称为order_typereq.param 调用使用的是'ordertype'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 2015-07-12
    • 2021-03-23
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多