Home  >  Article  >  Web Front-end  >  How to solve the problem of "cannot post" error when using submit form under Nodejs

How to solve the problem of "cannot post" error when using submit form under Nodejs

高洛峰
高洛峰Original
2016-12-06 11:16:161322browse

<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>

The registration form I wrote was submitted to the registerOK page using a post request. After submission, a "cannot post" error was displayed. The express template engine used, the code is as follows:

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

Later, I searched on the Internet and found that routing generally uses "get", but if you specify "post" for form submission, you also need to add one to the routing:

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

ok! The problem is solved!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn