Uso express e ho problemi a recuperare i dati del modulo da bodyParser. Qualunque cosa io faccia, viene sempre come un oggetto vuoto. Ecco il mio espresso generato app.js codice (l'unica cosa che ho aggiunto è stato il percorso app.post in basso):Node.js/Modulo espresso post req.body non funzionante
var express = require('express');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', function(req, res){
res.sendfile('./public/index.html');
});
app.post('/', function(req, res){
console.log(req.body);
res.sendfile('./public/index.html');
});
app.listen(3010);
Ecco il mio modulo HTML:
<!doctype html>
<html>
<body>
<form id="myform" action="/" method="post" enctype="application/x-www-form-urlencoded">
<input type="text" id="mytext" />
<input type="submit" id="mysubmit" />
</form>
</body>
</html>
Quando presento il forma, req.body è un oggetto vuoto {}
vale la pena notare che questo accade anche se mi tolgo l'enctype dalla forma tag
... c'è qualcosa che mi manca/facendo male?
Sto usando nodo v0.4.11 e v2.4.6 espresso
Grazie! Non so come ho trascurato che ... – binarymax