从自动保存脚本无法正确保存表单

时间:2016-03-02 20:07:34

标签: javascript php jquery forms

我有一个脚本,用于查找用户空闲,当它们持续x秒时,它会执行用户所在表单的提交(保存其数据,并将页面刷新回现有状态)形成)。出于某种原因,它刷新页面,而不是提交表单,导致表单丢失过程中的所有数据:P。我的代码中缺少什么东西吗?

脚本代码:

<!-- Set auto save timeout in milliseconds -->
<script type="text/javascript">
attachEvent(window,'load',function(){
  var idleSeconds = 5;
  var idleTimer;
  function resetTimer(){
    clearTimeout(idleTimer);
    idleTimer = setTimeout(whenUserIdle,idleSeconds*1000);
  }
  attachEvent(document.body,'mousemove',resetTimer);
  attachEvent(document.body,'keydown',resetTimer);
  attachEvent(document.body,'click',resetTimer);

  resetTimer(); // Start the timer when the page loads
});

function whenUserIdle(){
        document.project.submit();
        window.location = location.href;
}

function attachEvent(obj,evt,fnc,useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evt,fnc,!!useCapture);
    return true;
  } else if (obj.attachEvent){
    return obj.attachEvent("on"+evt,fnc);
  }
} 
</script> 

表格代码:

<form name="project" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="invoice-form" method="post"  class="invoice-form" role="form" novalidate> 

0 个答案:

没有答案