Automatic data saving issue
Where's no problem using an event to call an ajax call for a data saving function (saveData), but timed, automatic data saving by calling this function at different interval failed without error. See code below. Know why?
Thanks in advance.
- /* auto data saving; */
- // try 60 seconds first
- setTimeout("saveData()",60000);
- var saveData = function() {
- // use jQuery to send form
- $(document).ready(function() {
- $("#myform").submit(sendForm);
- return false;
- });
- console.log("after form submission by jquery");
- // iterate every 5 minutes
- // do 60 seconds for now
- setTimeout("saveData()",60000);
- }
- function sendForm() {
- console.log('sendForm called');
- $.post('mySavedata.cgi',$("#myform").serialize(),function(data,status){
- $("#inform").html('Saved!') });
- console.log('auto saved');
- setTimeout(function(){document.getElementById('inform').innerHTML = ""},3000);
- return false
- }