如何以HTML格式发回一个预设的数据字段?

时间:2021-10-13 19:32:19

I am working on a Node.js website. It maintains data about districts in a province. To edit district data, the admin types the district's name and the year and goes to a form (/edit?district=blah&year=2010) that has various fields about the district. How should I track which district and year the form was filled out for in the POST route's scope?

我正在Node.js网站上工作。它维护着一个省的地区数据。要编辑区域数据,管理员键入区域的名称和年份,然后转到包含有关区域的各种字段的表单(/ edit?district = blah&year = 2010)。如何在POST路径的范围内跟踪填写表格的区域和年份?

Basically I want to send back data in the current URL's parameters with a form POST.

基本上我想用表格POST发回当前URL参数中的数据。

2 个解决方案

#1


1  

Require body-parser module in your node server.. Then u can get the parameters posted in the body like request.body.paramName in any of your routes with post method.

在您的节点服务器中需要body-parser模块。然后,您可以使用post方法获取在任何路由中的request.body.paramName中发布的参数。

#2


1  

I added ?district=blah&year=2014 dynamically to the action field of my form and it works! I can get the two variables using req.query.district and req.query.year in the POST handler. Another way that people suggested to me was to have hidden input boxes on the page with the data pre-filled (using JS or any templating system you're using) and have it submit with the form.

我动态地将?district = blah&year = 2014添加到我的表单的操作字段中,它可以工作!我可以在POST处理程序中使用req.query.district和req.query.year获取这两个变量。人们向我建议的另一种方式是在页面上隐藏输入框并预先填充数据(使用JS或您正在使用的任何模板系统)并使用表单提交。

#1


1  

Require body-parser module in your node server.. Then u can get the parameters posted in the body like request.body.paramName in any of your routes with post method.

在您的节点服务器中需要body-parser模块。然后,您可以使用post方法获取在任何路由中的request.body.paramName中发布的参数。

#2


1  

I added ?district=blah&year=2014 dynamically to the action field of my form and it works! I can get the two variables using req.query.district and req.query.year in the POST handler. Another way that people suggested to me was to have hidden input boxes on the page with the data pre-filled (using JS or any templating system you're using) and have it submit with the form.

我动态地将?district = blah&year = 2014添加到我的表单的操作字段中,它可以工作!我可以在POST处理程序中使用req.query.district和req.query.year获取这两个变量。人们向我建议的另一种方式是在页面上隐藏输入框并预先填充数据(使用JS或您正在使用的任何模板系统)并使用表单提交。