在express.js中parsing服务器中的html值
我不知道什么时候在我以前的页面中工作不起作用。
input.form-control(type="text", name="names[]", autocomplete="off")
我想在我的服务器中检索这个值。 在我的其他页面中,我使用这个
console.log("value " + req.body["names[]"]);
我通常会得到一个名称的数组。 现在由于某种原因,我得到的是undefined我已经尝试了几个小时,我只是不知道什么是错的。
根据Express Docs, req.body
默认是undefined
的。 你需要一个像body-parser这样的中间件来抓取req
。
1) npm install body-parser
2)朝向服务器文件的顶部 – var bodyParser = require('body-parser');
3) var app = express()
包含app.use(bodyParser.json());