Automatic data saving issue

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.


  1.   /* auto data saving; */  
  2. // try 60 seconds first
  3. setTimeout("saveData()",60000);


  4.   var saveData = function() {
  5. // use jQuery to send form
  6. $(document).ready(function() { 
  7. $("#myform").submit(sendForm); 
  8. return false;
  9. });

  10. console.log("after form submission by jquery");
  11. // iterate every 5 minutes
  12. // do 60 seconds for now
  13. setTimeout("saveData()",60000);

  14. }

  15. function sendForm() { 
  16. console.log('sendForm called');
  17. $.post('mySavedata.cgi',$("#myform").serialize(),function(data,status){ 
  18. $("#inform").html('Saved!') });
  19. console.log('auto saved');

  20. setTimeout(function(){document.getElementById('inform').innerHTML = ""},3000);
  21.     return false 
  22. }