[英]php jquery ajax form submitted twice
我有一個使用jQuery驗證引擎和ajax的表單。 我正在使用zend作為框架。 但我有這個奇怪的情況。 從我的測試中,我知道在3種情況下,其中兩種是正確的。
1.當我填寫完所有輸入表格后按回車鍵時,該表格正常提交(一次)
2.當我在最后一個輸入框中時,我按Tab跳到“提交”按鈕,然后按Enter或單擊它,表單也正常提交(一次)
3.但是在我填寫完所有表單后,然后填寫驗證碼輸入框(光標仍在驗證碼輸入框中)並直接單擊提交按鈕,而不將光標位置移至其他元素,然后將表單提交兩次
我不明白為什么會這樣。 請幫助我解決這個問題。
這是我來自的html代碼:
<form id="kk_da" />
-- my form --
//here is the captcha
<div class="row">
<div class="col-md-12 col-lg-12">
<div class="mkk_form_captcha">
<span><strong>security code</strong>*</span>
<p>
<img src="<?php print $this->app->base_url ?>lib/captcha.php" id="captcha">
<br/><a href="#" onclick="" id="change-image"></a>
</p>
<p>
<a href="#" onclick="document.getElementById('captcha').src='<?php print $this->app->base_url ?>lib/captcha.php?'+Math.random();
return false" id="change-image">Not readable? Change text.</a>
</p>
<div class="mkk_field mkk_field_important <?php print $_cap ? 'mkk_field_alert' : ''; ?>
<?php if($this->error_captcha)print 'alert_captcha'; ?>">
<?php //print $this->form->getElement('captcha'); ?>
//the part above is described as follow
//and it happens that the ajax[ajaxCaptchaCall] is the problem
<input type="text" size="40" name="captcha" id="captcha"
class="validate[required,ajax[ajaxCaptchaCall]]" data-prompt-position="bottomRight"/>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 col-lg-12">
<div class="mkk_cart_buttons">
<input class="btn btn_blue" name="submit" type="submit" value="Buy" />
<input type="hidden" name="process_marker" value="process_order" />
<a href="<?php print $this->app->base_url ?>katalog/form" class="btn">back</a>
</div>
</div>
</div>
</form>
這是javascript
> jQuery(document).ready(function()
{
jQuery("#kk_da").validationEngine('attach',
{
onValidationComplete: function(form, status)
{
if (status == true)
{
var formData = jQuery('#kk_da').serialize();
jQuery.ajax(
{
url : '<?php print $this->app->base_url ?>katalog/checkout_process',
type : 'POST',
data : formData,
beforeSend : function()
{
loading_pop();
}
}).done(function(data)
{
loading_done();
if (data== 'success')
{
window.location = '<?php print $this->app->base_url ?>katalog/success';
}
}).fail(function()
{
loading_done();
}) ;
}
}
});
});
更新似乎我有問題。 看來問題出在“ ajax [ajaxCaptchaCall]”部分。 當我刪除該部分時,我的表格正常提交。 但這會使我的驗證碼無法工作,因為它繞過了它。 我該如何修復此部分,以便驗證碼有效並且僅提交一次表單?
可能是執行了兩次附加? jQuery(“#kk_da”)。validationEngine('attach',....)
外徑
序列化后嘗試設置form.status = false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.