我想使用 post 方法通过表单保存用户提交的数据,然后将其重定向到我本地机器上的另一个 html 页面,有什么方法可以使用 Node.js 实现这一点或表达我该怎么做?
这是表单的html代码:
<html>
<head></head>
<body>
<form action="post_register.html" method="POST">
university name:<input type="text" name="name" placeholder="University name"><br>
faculty Username:<input type="text" name="facul" placeholder="faculty username"><br>
password:<input type="password" name="password" placeholder="password"><br>
<button >register</button>
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
这是javascript文件:
var express = require("express");
var app = express();
var bodyparser=require("body-parser");
app.use(bodyparser.urlencoded({ extended: true }));
app.listen(3000);
app.get("/domain_register",function(req,res)
{
res.sendFile(__dirname+"/domain_register.html");
})
app.post("/post_register",function(req,res)
{
console.log(req.body);
res.end("yes");
});
Run Code Online (Sandbox Code Playgroud)
我想要的是在按下提交按钮后接收数据并将用户重定向到 post_register.html 文件。