Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 提交表单后,请求为空_Javascript_Node.js_Express - Fatal编程技术网

Javascript 提交表单后,请求为空

Javascript 提交表单后,请求为空,javascript,node.js,express,Javascript,Node.js,Express,我在翡翠中的形象是 extends layout block content h1= title form(action="create", method="post") div.input span.label Username input(type="text", name="username") div.input span.label Password

我在翡翠中的形象是

extends layout

block content
    h1= title
    form(action="create", method="post")
        div.input
            span.label Username
            input(type="text", name="username")
        div.input
            span.label Password
            input(type="password", name="password")
        div.actions
            input(type="submit", value="Create User")
我的index.js是

var express = require('express');
var bodyParser = require('body-parser')
var app = express();
app.route('/create')
    .get(function (req, res) {
        res.render('formUser', {
            title: 'Create User'
        });
    })
    .post(function (req, res) {

        console.log(req);

    });
为什么我的req.body或req.params为空?如何检索用户名和密码

谢谢,这还不够

var bodyParser = require('body-parser')
您还必须添加

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
这还不够

var bodyParser = require('body-parser')
您还必须添加

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

试试form(action=“/create”)@ChrisL这不是routedid的问题你需要一个body解析器吗?@charlietfl是的,我知道你的代码正在我的设置中工作,所以它必须在你的配置中,比如bodyparsertry form(action=“/create”)@ChrisL这不是routedid的问题你需要一个body解析器吗?@charlietfl是的,我不知道您的代码正在我的设置中工作,所以它必须在您的配置中,比如bodyparser