【发布时间】:2017-07-03 11:32:59
【问题描述】:
我对节点很陌生,所以请原谅它的简单性,但我不相信我掌握了基础知识。我正在尝试使用 bodyparser 提交表单,但收到错误消息:提交后无法获取 /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 '使用严格';
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 变量,但它无法识别该变量,我认为可以吗?
【问题讨论】:
标签: node.js express body-parser