[英]how do i make a form that when clicked submit to node.js express server
I tried but it doesn't work any idea?我试过了,但它没有任何想法?
this is my code:这是我的代码:
res.get("/signin", function(req, res) {
res.render("signin")
console.log(req.body)
}
when it shows undefined
and if I use body-parser it doesn't log when submitted instead it logs {}
to the console当它显示
undefined
并且如果我使用 body-parser 它在提交时不会记录,而是将{}
记录到控制台
Generally speaking — there are some exceptions but not when the client is a browser — you will not get a request body on a GET request.一般来说——有一些例外,但当客户端是浏览器时不会——你不会在 GET 请求上获得请求正文。
If you are submitting a <form>
then you need to make a POST request to get a body.如果您要提交
<form>
,则需要发出 POST 请求以获取正文。
method
attribute of the <form>
<form>
的method
属性.post()
route and not a .get()
route..post()
路由而不是.get()
路由配置 express。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.