4
我尝试了很多财产 '标题' 弄清楚为什么这引发了这样的错误:Expressjs POST错误:类型错误:无法读取的不确定
Configuring
Listening on 2000
TypeError: Cannot read property 'title' of undefined
at /home/abdulsattar/learning/node/express/index.js:9:20
的index.js:
var express = require("express"),
app = express.createServer();
app.get("/", function(req, res) {
res.send('<form action="/new" method="post"><input type="text" name="title" /><input type="submit" /></form>');
});
app.post("/new", function(req, res) {
res.send(req.body.title);
});
app.configure(function() {
console.log("Configuring");
app.use(express.bodyParser());
});
var port = process.env.PORT || 2000;
app.listen(port, function() {
console.log("Listening on " + port);
});
我已经读过快递需要bodyParser()
。我在use
以上,但它总是失败。我在版本2.5.8
和2.5.8
(认为可能是问题)上尝试过,但两个版本均失败。有什么我失踪?
哦,伙计!就是这样!我在处理程序之前移动了configure语句,并且它工作正常。非常感谢! – 2012-02-19 10:58:59