这样你应该尝试
const port = 3000;var express = require('express'), app = express();var bodyParser = require('body-parser');app.use(express.static(__dirname + '/public'));app.use(bodyParser.urlenpred({ extended: false}));app.use(bodyParser.json());app.get('/', function(req, res){ res.render('form');// if jade // You should use one of line depending on type of frontend you are with res.sendFile(__dirname + '/form.html'); //if html file is root directory res.sendFile("index.html"); //if html file is within public directory});app.post('/',function(req,res){ var username = req.body.username; var htmlData = 'Hello:' + username; res.send(htmlData); console.log(htmlData);});app.listen(port);
您将来应该记住的事情参考:
- 您将url编码扩展为true
- 您没有任何要求获取表格的请求
- 您正在使用HTML命名变量,这是不良做法之一
谢谢与欢呼
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)