Spring MVC:自动保存功能(jQuery、Ajax...)
我想在我的页面上实现“自动保存”功能。我真的不知道如何开始。我得到一个对象(带有任务列表)。我想每 20 秒提交一次表单,这样用户就不会丢失数据。它不必完全像那样。每次提交后,只要没有更改,提交按钮就应该被禁用。
我正在使用 Spring MVC。我做了一些研究,但我不是 jQuery、Spring 方面的专家......所以这对我来说非常复杂。一个提示或一个工作示例会对我有很大帮助。
这是一个相当复杂的表格(时间表)。一页上有 +/- 50 个文本框(最少,取决于可用任务的数量)
谢谢。
I'd like to implement a "auto-save" functionality on my page. I don't really know how to start though. I got one object (with a list of tasks). I'd like to submit the form every 20 seconds, so the users won't lose their data. It doesn't have to be exactly like that. After every submit the submit-button should be disabled as long as there are no changes.
I'm using Spring MVC. I did some research but I'm not an expert in jQuery, Spring... So it's all pretty complicated for me. A tip, or a working example would help me a lot.
It's a pretty complex form (a timesheet). There are +/- 50 textboxes on one page (minimum, depends on the number of tasks available)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道 spring mvc 是什么,但在 ASP.NET MVC 中我会执行以下操作:
我假设您的所有数据都在表单中,您为表单提供一个 ID,然后发布它:
});
检查鼠标移动、按键,如果 20 秒内未完成,则保存表单。
编辑:您还可以做的也许是,在他们填写的每个文本框之后,发布数据:如下所示:
http: //api.jquery.com/change/
在此示例中,您创建一个名为 Save 的控制器,一个名为 Textbox 的操作,您为文本框提供它必须保存的数据的 ID,并在更改时(在取消聚焦之后)文本框),它发布文本框 id 和该框的值。
然后在控制器中检索它:
I don't know what spring mvc is, but in ASP.NET MVC I would do the following:
I assume all your data is in a form, you give the form an ID, then post it:
});
Checks for mousemove, keypress, if this isnt done in 20 seconds then it saves the form.
Edit: What you could also do maybe is, after every textbox they fill in, post the data: as followed:
http://api.jquery.com/change/
In this example, you make a controller called Save, action called Textbox, you give the textbox the ID of data that it has to save, and on change (after un focussing the textbox), it posts the textbox id, and the value of the box.
then in the controller you retrieve it:
下面的 Js 脚本将帮助您在表单字段更改时进行 ajax 调用。
Below Js script will help you to make ajax call when ever form field changes.