这是我的代码:
var express = require('express');
var app = express();
app.get('/:name', function(req,res){
res.setHeader('Content-Type','text/html');
res.send('<form action="/" method="POST"><input type="text" name="self"/><input type="submit"/></form>');
});
app.post('/',function(req,res){
res.send(req.body.self);
});
app.listen(8080);
我打电话给 localhost:8080/examplename
并在输入中写一些东西,然后单击提交按钮。它转到 localhost:8080 但节点返回错误如下:
TypeError: Cannot read property 'self' of undefined
at /home/yusuf/Masaüstü/node/ue.js:10:19
at callbacks (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:160:37)
at param (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:134:11)
at pass (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:141:5)
at Router._dispatch (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:169:4)
at Object.router [as handle] (/home/yusuf/Masaüstü/node/node_modules/express/lib/router/index.js:32:10)
at next (/home/yusuf/Masaüstü/node/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.expressInit [as handle] (/home/yusuf/Masaüstü/node/node_modules/express/lib/middleware.js:31:5)
at next (/home/yusuf/Masaüstü/node/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.query [as handle] (/home/yusuf/Masaüstü/node/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)