Abd*_*med 4 post node.js express
我试了很多来弄清楚为什么会引发这个错误:
Configuring
Listening on 2000
TypeError: Cannot read property 'title' of undefined
at /home/abdulsattar/learning/node/express/index.js:9:20
Run Code Online (Sandbox Code Playgroud)
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);
});
Run Code Online (Sandbox Code Playgroud)
我读过快递需要的bodyParser().我use在上面,但它总是失败.我试了一下版本2.5.8和2.5.8(以为可能是问题),但它未能在两个版本.有什么我想念的吗?
JP *_*son 12
我的预感,尝试在app.get和app.post之前移动app.configure语句.bodyParser中间件未被调用.另外,为了安全添加enctype到表单,不应该是必要的,但无论如何:application/x-www-form-urlencoded.
让我知道...
| 归档时间: |
|
| 查看次数: |
10041 次 |
| 最近记录: |