我知道这个问题已经被回答了几百次,但是我已经遇到了大量潜在的解决方案,但它们似乎都没有在我的实例中起作用.
以下是我提交表格的表格和代码.它会触发PHP脚本.现在我知道脚本本身不是提交的原因,因为我手动尝试了表单,它只提交一次.
jQuery代码的第一部分涉及打开一个灯箱并从下面的表中提取值,我已将其包含在内,无论出于何种原因它都是潜在的问题.
jQuery代码:
$(document).ready(function(){ $('.form_error').hide(); $('a.launch-1').click(function() { var launcher = $(this).attr('id'),launcher = launcher.split('_'); launcher,launcher[1],$('td .'+launcher[1]); $('.'+launcher[1]).each(function(){ var field = $(this).attr('data-name'),fieldValue = $(this).html(); if(field === 'InvoiceID'){ $("#prevIoUspaymentsload").load("functions/invoicing_payments_received.PHP?invoice="+fieldValue,null,function() { $("#prevIoUspaymentsloader").hide(); }); } else if(field === 'InvoiceNumber'){ $("#addinvoicenum").html(fieldValue); } $('#'+field).val(fieldValue); }); }); $("#addpayment_submit").click(function(event) { $('.form_error').hide(); var amount = $("input#amount").val(); if (amount == "") { $("#amount_error").show(); $("input#amount").focus(); return false; } date = $("input#date").val(); if (date == "") { $("#date_error").show(); $("input#date").focus(); return false; } credit = $("input#credit").val(); invoiceID = $("input#InvoiceID").val(); by = $("input#by").val(); dataString = 'amount='+ amount + '&date=' + date + '&credit=' + credit + '&InvoiceID=' + invoiceID + '&by=' + by; $.ajax({ type: "POST",url: "functions/invoicing_payments_make.PHP",data: dataString,success: function(result) { if(result == 1){ $('#payment_window_message_success').fadeIn(300); $('#payment_window_message_success').delay(5000).fadeOut(700); return false; } else { $('#payment_window_message_error_mes').html(result); $('#payment_window_message_error').fadeIn(300); $('#payment_window_message_error').delay(5000).fadeOut(700); return false; } },error: function() { $('#payment_window_message_error_mes').html("An error occured,form was not submitted"); $('#payment_window_message_error').fadeIn(300); $('#payment_window_message_error').delay(5000).fadeOut(700); } }); return false; }); });
这是html表单:
<div id="makepayment_form"> <form name="payment" id="payment" class="halfBoxform"> <input type="hidden" name="InvoiceID" id="InvoiceID" /> <input type="hidden" name="by" id="by" value="<?PHP echo $userInfo_ID; ?>" /> <fieldset> <label for="amount" class="label">Amount:</label> <input type="text" id="amount" name="amount" value="0.00" /> <p class="form_error clearb red input" id="amount_error">This field is required.</p> <label for="credit" class="label">Credit:</label> <input type="text" id="credit" name="credit" /> <label for="amount" class="label">Date:</label> <input type="text" id="date" name="date" /> <p class="form_error clearb red input" id="date_error">This field is required.</p> </fieldset> <input type="submit" class="submit" value="Add Payment" id="addpayment_submit"> </form> </div>
希望有人能帮忙,因为它让我疯狂.谢谢.
有时,您不仅要阻止处理事件的默认行为,还要防止执行任何下游事件处理程序链.
这可以通过在
原文链接:https://www.f2er.com/php/133452.html这可以通过在
event.preventDefault()
之外调用
event.stopImmediatePropagation()
来完成.
示例代码:
$("#addpayment_submit").on('submit',function(event) { event.preventDefault(); event.stopImmediatePropagation(); });