通过 $(“#formname”).submit(); 重复表单提交
Duplicate form submition through $("#formname").submit();
我有一行HTML下拉列表,每当用户选择其中一个选项时,它都会通过提交表单的类调用jQuery函数。
<form id="workorderform" action="saveworkorder.php" method="post">
<select name="applicationtype" class="checkvalueonchange savevalueonchange">
<option></option>
<option value="Uplift" <?php echo ($wo['applicationtype']=='Uplift')?'selected':''; ?>>Uplift</option>
</select>
</form>
savevalueonchange
类调用
$(".savevalueonchange").change(function() {
autoSave();
});
然后调用
function autoSave() {
if($("#wostatus").val()=='open'){
$("#workorderform").submit();
}
}
将信息发布到saveworkorder.php
//remove existing chargecodes
$sql = "DELETE FROM workorderchargecodes WHERE compresscoid = '".trim($_REQUEST['formid'])."'";
mssql_query($sql, $dbconn);
//now save chargecodes
$code_prefix = 'code_';
foreach($_POST as $thisPostKey => $thisPostValue) {
if((substr($thisPostKey, 0, strlen($code_prefix)))==$code_prefix) {
if(trim($thisPostValue)!=''):
$exists=false;
$sql = "SELECT * FROM workorderchargecodes WHERE compresscoid='".trim($_REQUEST['formid'])."' AND code='".substr($thisPostKey, strlen($code_prefix), strlen($thisPostKey))."'";
$res = mssql_query($sql, $dbconn);
while($arr = mssql_fetch_assoc($res)){
$exists=true;
}
if($exists==false){
$sql = "INSERT INTO workorderchargecodes (
compresscoid,
code,
time
) VALUES (
'".trim($_REQUEST['formid'])."',
'".substr($thisPostKey, strlen($code_prefix), strlen($thisPostKey))."', '".$thisPostValue."'
)";
mssql_query($sql, $dbconn);
}
endif;
}
}
如您所见,在将代码插入数据库之前,我正在从数据库中选择代码,并且不知何故仍然得到重复的费用代码。我已经搞砸了几个月了,它仍然不断发生。
有什么想法吗?
尝试在 autosave() 中添加return false;
,如下所示:
function autoSave() {
if($("#wostatus").val()=='open'){
$("#workorderform").submit();
return false; // add here
}
}
它将阻止提交两次。
<form id="workorderform" action="saveworkorder.php" method="post" onsubmit="return false;">
<select name="applicationtype" class="checkvalueonchange savevalueonchange">
<option></option>
<option value="Uplift" <?php echo ($wo['applicationtype']=='Uplift')?'selected':''; ?>>Uplift</option>
</select>
</form>
使用此表单
它使用obsubmit="return false;"
相关文章:
- HTML表单提交时未执行外部函数
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 将图像上传ajax与表单提交ajax相结合
- Javascript无法处理表单提交
- 如何在我的情况下禁用表单提交
- 通过 $(“#formname”).submit(); 重复表单提交
- 表单提交事件中this.submit()的行为
- 正在尝试使用.submit在表单提交上激发jquery validate
- $(id).submit() 不会触发表单提交
- JavaScript 表单提交带有一个名为 submit 的字段
- Javascript submit()没有't触发表单提交
- 如何在form.submit处理程序(jquery)中的异步回调中触发表单提交
- jQuery .submit()在表单提交时没有被调用
- 如何在iframe表单提交后使用submit() jquery调用函数
- Jquery .submit(handler)似乎没有检测表单提交
- 通过.submit表单提交多个选项卡内容
- JavaScript表单提交不发送输入类型=submit的值
- 带有spin.js的jQuery submit()是否阻止表单提交
- Javascript 返回 false;不会取消另一个 .submit jQuery 调用的表单提交
- 使用submit eventlistener停止表单提交