Node.js express.js-req.body?
我是js的新手, 我在我读的代码中看到了很多Node.js express.js-req.body?,node.js,express,Node.js,Express,我是js的新手, 我在我读的代码中看到了很多 _.pick(req.body, ' ' , ' ') req.body做什么? 什么时候可以说req.body.something?req.body包含作为POST请求一部分从客户端发送的参数。看 (req.body,,“”)-->这里req是函数的参数,使用此参数可以访问url上的属性。 看看这个例子 假设这是表单 输入名称: 提交 因此,如果您想访问由用户端填写的名称。 因此,你可以 这样做->console.log(req.body.na
_.pick(req.body, ' ' , ' ')
req.body做什么?
什么时候可以说req.body.something?
req.body
包含作为POST请求一部分从客户端发送的参数。看
(req.body,,“”)-->这里req是函数的参数,使用此参数可以访问url上的属性。
看看这个例子
假设这是表单
输入名称:
提交
因此,如果您想访问由用户端填写的名称。
因此,你可以
这样做->console.log(req.body.name);--这将在控制台中打印名称(属性)。
请为您的问题添加更多详细信息?如果从服务器而不是客户端发送了一些内容,会发生什么情况?当您从客户端收到一些请求,而从服务器收到其他请求时,如何协调这两种情况?
// POST user[name]=tobi&user[email]=tobi@learnboost.com
req.body.user.name
// => "tobi"
req.body.user.email
// => "tobi@learnboost.com"
// POST { "name": "tobi" }
req.body.name
// => "tobi"
(req.body, ' ' , ' ') --> here req is the parameter of your function and using this parameter your can access the properties over then url.
so look this example
suppose this is form
<form>
enter the name : <input type="text" name="name">
<button type ="submit"> submit </button>
</form>
so if you want to access the name -- which is filled by the user end.
so for this you can
do like this-> console.log(req.body.name); -- this will print the name (property) in console.