2014-09-22 65 views
0

我需要發送一些隱藏變量到struts控制器上自動提交表單。我發送的變量很好,但因爲我已經在文檔中提交表單就緒函數。表單無限次提交。我需要在第一次提交後停止提交。有什麼建議麼 ?以下是我的嘗試。表單自動提交多次

代碼

<script> 
$(document).ready (function() { 
document.getElementById ('action').value ='hello'; 
document.getElementById ('myform').submit(); 
}) 
</script> 

<form action="/rlogin" id="myform"> 
<input type=hidden id=user value=you> 
<input type=hidden id=action /> 

回答

0

檢查weither提交已創建或不創建後一個變量。

$(document).ready (function() { 
    if (typeof mySent == 'undefined') { 
     document.getElementById ('action').value ='hello'; 
     document.getElementById ('myform').submit(); 
     mySent = true; 
    } 
}