Node.js / Express POST数据未发送

时间:2017-02-04 10:56:53

标签: javascript node.js

由于某种原因,我无法发送/接收POST数据。我试图简单地在/ save路径中调试post.log我错过了什么?

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)

路线:

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;

1 个答案:

答案 0 :(得分:1)

您的表单控件没有$("form").submit(function (e) { e.preventDefault(); var error = ""; if ($("#subject").val() == ""); { error += "<p>The subject area is required</p>"; } $("#error").html(error); }); 属性。没有名称,它们就无法成功,也不会被包含在提交的数据中。

(您的表单本身具有<meta-data android:name="io.fabric.ApiKey" android:value="XXXXXXXXXXXXXXX" /> 属性,但这是旧版标记,您应该使用name代替。仅表单控件(如nameid)应该有input s)