I’m trying to natively submit a form using the code below:
$('#invoices-bundle').submit(function(e) {
e.preventDefault(); // don't submit multiple times
this.submit();
$.post('php/seller/invoice/invoice_print_batch.php', function(data){
$('#added-invoices').html(data);
});// use the native submit method of the form element
});
After the submit(); I want to populate the DOM with the contents of my PHP script. The weird thins is the DOM doesn’t get populated the first time I submit the form but the second time and everytime after that.
Don’t know why this happens! Any suggestions?
Thanks!
After you submit form with
this.submit();, the rest of the codes will be useless. The page gonna be change or refresh and after ajax codes will be break. Make form to post as ajax, instead of regular form submit or change the order of codes, putsubmit()at the end.