html部件
<!DOCTYPE html>
<html lang="en">
<head>
<title>Calculator</title>
</head>
<body>
<h1>Calculator</h1>
<form action="/index.html" method="POST">
<input type="text" name="num1" placeholder="First Number">
<input type="text" name="num2" placeholder="Second Number">
<button type="submit" name="submit">Calculate</button>
</form>
</body>
</html>
节点js部分
const express = require("express");
const bP = require("body-parser");
const app = express();
app.use(bP.urlencoded({extended: true}));
app.get("/",function(req,res){
res.sendFile(__dirname + "/index.html");
});
app.post("/",function(req,res){
res.send("Thanks for posting that");
});
app.listen(3000,function(){
console.log("The server is started on port 3000.");
});
index.html文件包含两个输入字段,采用两个数字和一个提交按钮。点击提交按钮,我得到输出
无法POST/index.html
我刚刚更正了app.post((方法
修正前是这样的:
res.send("Thanks for posting that");
});```
After correction:
```app.post("/index.html",function(req,res){
res.send("Thanks for posting that");
});```