jquery表单提交两次

时间:2015-06-12 17:41:21

标签: forms double submit

我用ajax创建了一个表单提交,但它提交了两次???
有谁知道什么是错的?

这是我的代码:

  var form = $('#myForm'); // contact form
  var submit = $('#offertesturen');  // submit button
  var alert = $('.alert'); // alert div for show alert message

  $('#myForm')
  .on('invalid.fndtn.abide', function () {
   var invalid_fields = $(this).find('[data-invalid]');
   console.log(invalid_fields);
  })

 .on('valid.fndtn.abide', function(e) {
e.preventDefault(); // prevent default form submit

$.ajax({
  url: 'send_form_email.php', // form action url
  type: 'POST', // form submit method get/post
  dataType: 'html', // request type html/json/xml
  data: form.serialize(), // serialize form data 
  beforeSend: function() {
    alert.fadeOut();
    submit.html('.....'); // change submit button text
  },

  success: function(data) {
    alert.html(data).fadeIn(); // fade in response data
    form.trigger('reset'); // reset form
    submit.html('Aanvragen!'); // reset submit button text
    $(document).scrollTop(0);
    $('#secondModal').foundation('reveal', 'open');
  },

  error: function(e) {
    console.log(e)
  }
 });
});

0 个答案:

没有答案