Nodejs下用submit提交表单提示cannot post错误的解决方法

Karima ·
更新时间:2024-09-21
· 899 次阅读

<span style="font-size:18px;"><form action="/registOK" method="get"> <p>用户名:<input type="text" id="userName" name="userName"></p> <p>密码:<input type="password" id="passWord" name="passWord"></p> <p><input type="submit" value="注册" id="zhuce"></p></form></span>

我写的注册表单,用post请求提交到registOK页面,提交后提示cannot post错误。用的express模板引擎,代码如下:

app.get("/registOK",function (req,res,next) { res.render("registOK"); });

后来在网上查找发现,路由一般使用“get”就可以,但如果表单提交你指定了“post”,路由上也得加一条:

<span style="font-size:18px;">app.post("/registOK",function (req,res,next) { res.render("registOK"); });</span>

ok!问题解决了!



表单 方法 submit post

需要 登录 后方可回复, 如果你还没有账号请 注册新账号