定期自动保存表格 [英] Periodically autosave form
本文介绍了定期自动保存表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在后台实现表单的定期保存?和gmail一样的事情。
How to implement a periodical save of a form in the background? Same kinda thing that gmail does.
推荐答案
setInterval(function(){
var form = $('#my-form-id');
var method = form.attr('method').toLowerCase(); // "get" or "post"
var action = form.attr('action'); // url to submit to
$[method](action, form.serialize(), function(data){
// Do something with the server response data
// Or at least let the user know it saved
});
},10000); // do it every 10 seconds
如果你不想使用表格的方法,但总是想使用'post',然后使用:
If you don't want to use the method of the form, but always want to use 'post', then use:
$.post(action, form.serialize(), ... );
并且,如果您想为自动保存提供自己的操作,该操作不同于实际保存:
And, if you want to supply your own action for the autosave that is different from the action for the actual save:
$.post("/autosave/comments", form.serialize(), ... );
这篇关于定期自动保存表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文