具有取消和提交按钮的Bootstrap模式弹出表单,无论单击哪个按钮提交表单

我正在尝试解决引导模态弹出窗口的问题。我在表单中有两个按钮,一个要取消,另一个要提交表单。 如果我单击“取消”按钮,则仍会提交表单。谁能看到我要去哪里错了。

我的表格

<form  name="DeleteConferenceBooking" id="Conference_Delete" method="post" autocomplete="off"  enctype="multipart/form-data" role="form" data-toggle="validator">
<input name="RecordID" type="text" id="ConfDeleteRecordID">
<button type="button" class="tn btn-warning-edit btn-xs" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-secondary-edit btn-xs submit-button">Continue</button>
</form>

我的Jquery提交代码

$(document).ready (function () {
  $('#Conference_Delete').on('click',function(e){
    e.preventDefault();
    $('#open_delete_conference_booking_data_modal').toggle();
    var recordid = $('#ConfDeleteRecordID').val();
    console.log("CONFERENCE DELETE RECORDID",recordid);
    var form = this;
    var formData = new FormData(form);
    formData.append("RecordID",recordid);
    $.ajax({
        url: 'conf_bookings_delete.php',type: 'POST',data: formData,cache: false,contentType: false,processData: false,success: function(data){
          var result = JSON.stringify(data); 
          result = JSON.parse(result);
          console.log("RESULT",result);
          $("#open_delete_conference_booking_data_modal").modal('hide');
          $("#open_edit_data_modal").modal('hide');
          $('#userTable').DataTable().ajax.reload();
        }
    }); 
  });   
}); 

在此先感谢您的帮助和时间

linshi0 回答:具有取消和提交按钮的Bootstrap模式弹出表单,无论单击哪个按钮提交表单

将事件更改为提交而不是单击。

$(document).ready (function () {
  $('#Conference_Delete').on('submit',function(e){
    e.preventDefault();
    $('#open_delete_conference_booking_data_modal').toggle();
    var recordid = $('#ConfDeleteRecordID').val();
    console.log("CONFERENCE DELETE RECORDID",recordid);
    var form = this;
    var formData = new FormData(form);
    formData.append("RecordID",recordid);
    $.ajax({
        url: 'conf_bookings_delete.php',type: 'POST',data: formData,cache: false,contentType: false,processData: false,success: function(data){
          var result = JSON.stringify(data); 
          result = JSON.parse(result);
          console.log("RESULT",result);
          $("#open_delete_conference_booking_data_modal").modal('hide');
          $("#open_edit_data_modal").modal('hide');
          $('#userTable').DataTable().ajax.reload();
        }
    }); 
  });   
}); 
本文链接:https://www.f2er.com/3150129.html

大家都在问