私はexpressを使用しており、bodyParserからフォームデータを取得することに問題があります。私が何をしても、それは常に空のオブジェクトとして現れます。私が提出した場合Node.js/Express form post req.body not working
<!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>
:ここ
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);
が私のHTMLフォームである:ここに私の急行はapp.jsコードを生成している(私は追加唯一のことは、一番下にapp.postルートがありました)フォームは、req.bodyは空のオブジェクト{}
その価値は、私はformタグ
からenctype属性を削除しても、この問題が発生したことは注目です...私が間違っている/行方不明です何かはありますか?
Iは、HTTPポストの本体はname
属性を持つすべてのフォームコントロールのキー/値のハッシュであり、値は、ノードv0.4.11とエクスプレスv2.4.6
ありがとうございました!どのように私はそれを見落としたかわからない... – binarymax