How to implement a periodical save of a form in the background? Same kinda thing that gmail does.
When you fill out a Google Form in your Google account, your progress is automatically saved as a draft for 30 days. This means if you can't complete a form or need to switch devices, you don't have to start over the next time you open the form. Important: If you're offline, autosave doesn't work.
verb (used without object), au·to·saved, au·to·sav·ing. to be automatically saved: Most video games autosave after each new level.
To disable this feature, within Google Forms, go to Settings > Presentation > Restrictions and select “Disable autosave for all respondents”.
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
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(), ... );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With