2014-09-22 64 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; 
    } 
}