简体   繁体   English

如何动态建立列表并将用户选择的值从HTML表单传递/保存到服务器?

[英]How build a list dynamically and pass/save user selected values from an HTML form to server?

I think in this case I need to write a client side script that onpageload/onchange gets options from server & builds a list dynamically. 我认为在这种情况下,我需要编写一个客户端脚本,使onpageload / onchange从服务器获取选项并动态建立列表。 & stores new options to server via some JavaScript script. 并通过一些JavaScript脚本将新选项存储到服务器。 I will prefer to save user input in a file on server. 我将更喜欢将用户输入保存在服务器上的文件中。 I will be very thankful for any help. 我将非常感谢您的帮助。

Here is the stack we use for our web app and that works more or less the way you describe: 这是我们用于网络应用程序的堆栈,它或多或少地以您描述的方式工作:

  1. the user load an HTML page 用户加载一个HTML页面
  2. the page make an ajax call and get the options as a JSON(either it exists already in the database, or a new option set is generated) 该页面进行ajax调用并以JSON格式获取选项(它已经存在于数据库中,或者生成了一个新的选项集)
  3. the json is rendered using a JS templating engine ( PURE in our case) json是使用JS模板引擎渲染的(在我们的示例中为PURE
  4. the user change something 用户改变一些东西
  5. the same JSON is modified and sent by a POST to the server 修改了相同的JSON,并通过POST将其发送到服务器
  6. the server read that JSON and store it in the database(you would write the data to your file). 服务器读取该JSON并将其存储在数据库中(您会将数据写入文件中)。 And then go back to the step 4, to wait for another user change. 然后返回到步骤4,以等待另一个用户更改。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM