javascript - Node js post data is undefined -
this in app.js
file...
var routes = require('./routes'); var user = require('./routes/user'); var reg = require('./routes/register'); var bodyparser = require('body-parser'); app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: true })); ... ... app.get('/', routes.index); app.get('/users', user.list); app.get('/register', reg.register); app.post('/signup', reg.postregister);
in register.js
file rendering new page using get
, , trying access post
data page using post
function...
exports.register = function (req, res){ res.render('register.jade', { title: 'register' }); } exports.postregister = function (req, res) { console.log(req.body.reg_name); }
the get
works, , post
function called console logs undefined
, cannot figure out why. html file register.js
trying access...
form(name="login", method="post", action='/signup', enctype="multipart/form-data") div.personal span.label name input(type="text", name="reg_name") input(type="submit", value="submit")
why getting undefined
?
remove attribute [enctype="multipart/form-data"]
Comments
Post a Comment