javascript - jQuery submit form multiple times -


i have following bootstrap contact form:

     <form id="contactform" class="form-horizontal" data-async data-target="#contact" action="/contact.php" method="post">          (...)          <button class="btn btn-primary pull-right" type="submit">send</button>      </form> 

and jquery code:

$('form[data-async]').on('submit', function(event) {     var $form = $(this);     var $target = $($form.attr('data-target'));      $.ajax({         type: $form.attr('method'),         url: $form.attr('action'),         data: $form.serialize(),          success: function(data, status) {             $target.html(data);         }     });      event.preventdefault(); }); 

i can submit form , ajax response once second time try it loads contact.php in navigator. don't because event.preventdefault() should prevent this. how can make multiple ajax calls work?

try form+ajax without complexities given. if works code.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -