javascript - How to submit form using ajax and normal POST in same time?
453
I've form that submit data to external URL and the same time I want to save in my database. I've triedajax
submit and try to sumbit normalPOST
in ajax success.
Here my code:
<form action="http://www.blabla/post" method="post" id="myfrom">
.....
....
</form>
<script>
$('#myfrom').submit(function() {
e.preventDefault();
$.ajax({
url: 'admin-ajax.php',
type: 'POST',
dataType: 'html',
data: $('#myfrom').serialize(),
success: function() {
$('#myfrom').submit();
},
error: function(e) {
console.log(e);
}
});
});
</script>
But here Ajax is not working form will submit normal post only.
Answer
Solution:
change this:
to this:
You have not passed the event in the argument so form gets submitted.
This is another way as i see:
Answer
Solution:
you try this one. make a button in place of submit button.
Answer
Solution:
return false after ajax call to stop the normal form submit like this: