jquery form submits twice

298 Views Asked by At

I've created a form submit with ajax, but it submits twice???
Is there anyone who knows whats going wrong?

This is my code:

  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

There are 0 best solutions below