【发布时间】:2021-05-30 15:49:30
【问题描述】:
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 文件包含两个带有两个数字的输入字段和一个提交按钮。 单击提交按钮时,我得到了输出
无法发布 /index.html
【问题讨论】:
-
在您的表单中您是否尝试执行
action="/index.html"? -
如果您显示相关的前端代码,人们将能够更好地帮助您。
-
是的,我已经将 action 属性定义为,action = "/index.html" 仍然 app.post() 不起作用。