For some reason I am not able to send/receive POST data. I am trying to simply console.log the post data in the /save route Am I missing something?
index.jade:
extends layout
block content
div#startbutton
p start
div#endbutton
p stop
div#resetbutton
p reset
div#savebutton
p save
div#container
form(name='textform', method='post', action='/save')
input(type="submit", value="Submit")
textarea#thetextarea(rows=20 cols=30)
route:
var express = require('express');
var bodyParser = require('body-parser');
var router = express.Router();
router.use(bodyParser.urlencoded({ extended: false }));
router.use(bodyParser.json());
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Recorder Prototype' });
});
router.post('/save', function(req, res, next) {
console.log(req.body.thetextarea);
console.log(req.body);
console.log("=============================");
res.render('data', { title: 'Save', textstring: req.body.thetextarea });
});
module.exports = router;
Your form controls have no name
attributes. Without names, they cannot be successful and won't be included in the submitted data.
(Your form itself does have a name
attribute, but that is legacy markup and you should use id
instead. Only form controls (like input
and textarea
) should have name
s)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.