2014-11-22 53 views
0

我建立使用快遞4.我試圖得到一些數據表單的應用程序,但它總是返回空{}快遞4:POST方法

我在應用中的以下行。 JS

var bodyParser = require('body-parser'); 

var signup = require('./routes/signup'); 

app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({ extended: true })); 

app.use('/signup', signup); 

我的路由處理,signup.js

var express = require('express'); 
var router = express.Router(); 

// signup routing handler 
router.get('/', function (req, res) { 
    res.render('signup'); 
}); 
router.post('/', function (req, res) { 
    console.log(JSON.stringify(req.body)); 
    res.send('Foo Bar!'); 
}); 

module.exports = router; 

我的形式,在玉格式:

form.form-horizontal(method='post') 
    .form-group 
     label.col-sm-2.control-label(for='firstName') 
      | First Name: 
       .col-sm-10 
        input.form-control(#firstName, type='text', placeholder='John') 
    .form-group 
     .col-sm-2.control-label 
      button.btn.btn-default(type='submit') 
         | Sign Up! 
+1

你需要給名字的輸入字段。請參閱http://stackoverflow.com/questions/10151837/submit-jade-form – 2014-11-22 19:17:17

回答

0

在玉文件的輸入需要爲了名有鍵在JSON

像這樣:

form.form-horizontal(method='post') 
.form-group 
    label.col-sm-2.control-label(for='firstName') 
     | First Name: 
      .col-sm-10 
       input.form-control(#firstName, 
            type='text', 
            placeholder='John', 
            name='firstName') 
.form-group 
    .col-sm-2.control-label 
     button.btn.btn-default(type='submit') 
        | Sign Up!