Bra*_*ram 3 forms post node.js express
我想在Express/Node.js中获取BOTH POST和GET请求的参数值.我知道明确获取POST或GET数据的方法,但我想要一些适合两者的方法.这可能在一行代码中吗?
express.all('/page', function(req, res) {
var thing = req.body.thing; // only works for POST requests, not GET!
});
Run Code Online (Sandbox Code Playgroud)
谢谢
你在找req.param(name, [defaultValue]).
Lookup is performed in the following order:
req.params
req.body
req.query
Run Code Online (Sandbox Code Playgroud)
POST是 req.body
GET是 req.query
express.all('/page', function(req, res) {
var thing = req.param('thing');
});
Run Code Online (Sandbox Code Playgroud)
或者您可以使用req.body和req.query直接.
| 归档时间: |
|
| 查看次数: |
4440 次 |
| 最近记录: |