我对节点很新,所以请原谅我的简单,但我不相信我正在抓住基本面。我正在尝试使用bodyparser提交表单,我收到错误消息:GET / newpoll?pollName =& option1 =& option2 =& submitButton =我提交后。
server.js
'use strict';
var express = require('express');
var routes = require('./app/routes/index.js');
var session = require('express-session');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
routes(app, passport);
var port = process.env.PORT || 8080;
app.listen(port, function () {
console.log('Node.js listening on port ' + port + '...');
});
index.js 'use strict';
var path = process.cwd();
var ClickHandler = require(path + '/app/controllers/clickHandler.server.js');
var bodyParser = require('body-parser');
module.exports = function (app, passport) {
app.route('/newpoll')
.post(isLoggedIn, bodyParser, function(req, res) {
//console.log(req.pollName);
console.log(req.option1);
console.log(req.option2);
});
};
form action =“/ newpoll”。我尝试在路由器中没有bodyparser变量,但它没有识别变量,我以为会这样?