我有下面的代碼,當用戶空閒時,它應該自動提交(保存)名爲「project」的表單。這是我在教程網站上找到的代碼(忘記名稱),我試過了,它只刷新頁面?空閒時自動保存表格
<!-- 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>
我將添加我的表單代碼 – Steven
我知道它刷新,它應該是,它只是沒有提交它應該的形式 – Steven
這是因爲你在提交之前重新加載頁面,你需要在重新加載頁面之前發送數據 –