简体   繁体   中英

express.js express-resource POST (create) req.body is undefined

Windows.

Node 0.8 express.js/express-resource

// Configuration of Express Application for all environments
app.configure(function(){
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(express.bodyParser());
    //app.use(require('connect').bodyParser());
    app.use(express.methodOverride());

    app.use(express.static(__dirname + '/public')); // for static assets (css)
    app.use(express.static(__dirname + '/..')); // for static assets (css)

    app.use(app.router);
});
app.resource("data", require('.....js'));

Send POST /data (in FireBug): account[foo] bar name New

in created method (req, res)

req.body is undefined.

There are some talks in the internet about a like problem (with bodyParser or Router), but I could not fix it.

A

Solved. Just in case for someone: I called app.get(..) before bodyParser middleware.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM