【发布时间】:2021-08-17 14:53:58
【问题描述】:
我写了这个名为Post_handling.ejs的ejs文件:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>POST-Handling Page</title>
</head>
<body>
<h1>Register here!!!</h1>
<form class="" method="POST" action="/Post_handling">
<label for="">City:</label>
<input type="text" name="city" value="">
<label for="">State:</label>
<input type="text" name="state" value="">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
我已经编写了这个 node.js 代码来处理 POST 请求:
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.set('view engine', 'ejs');
app.post('/Post_handling', urlencodedParser, function(request, response){
response.render('Post_handling');
console.log(request.body);
});
app.listen('3000');
console.log('Hello user! Now you are listening on port 3000 at address 127.0.0.1:3000\nPress ctrl+C to stop.');
当我运行 node.js 代码时,我得到这个错误:
无法 GET /Post_handling
【问题讨论】:
标签: javascript html node.js express