简体   繁体   English

我如何制作一个表单,点击后提交到 node.js 快递服务器

[英]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 请求以获取正文。

  • Set the method attribute of the <form>设置<form>method属性
  • Configure express with a .post() route and not a .get() route.使用.post()路由而不是.get()路由配置 express。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用node.js和express.js从表单发出和删除请求? - How can I make put and delete requests from a form using node.js and express.js? 在node.js中单击时,如何使这些链接下载文件? - How to make these links to download files when clicked in node.js? 使用Node.js和Express提交表单时如何发送日期 - How to send date when submitting a form with Node.js and Express 如何使我的会话在 Node.js Express 中持续跨子域? - How do I make my sessions last cross-subdomain in Node.js Express? 如何<a>在 node.js 中</a>获取点击<a>链接</a>的名称<a>?</a> - How do I get the name of a clicked <a> link in node.js? 使用 Express 和表单输入提交在 Node.js 上执行查询 - Execute Query on Node.js Using Express and Form Input Submit 如何编写服务器端的node.js / express方法? - How do I write a server side node.js / express method? 我在同一页面上有一个表格和表格,如何使用表格来更新表格。 Express / Node.js - I have a form and table on same page, how do i use the form to update the table. Express / Node.js 在 Node.js 中,如何让一台服务器调用另一台服务器上的函数? - In Node.js, how do I make one server call a function on another server? 如何通过 node.js 服务器路由 html 表单提交以更新 a.js 文件中变量的值 - How to route an html form submit through a node.js server to update the value of a variable in a .js file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM