Home >Web Front-end >JS Tutorial >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
2017-01-04 16:57:033683browse

<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 must also 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!

For more related articles on how to solve the "cannot post" error when using submit to submit a form under Nodejs, please pay attention to the PHP Chinese website!


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