Call a function after a form is submitted using JavaScript / jQuery
forms, javascript, jquery
Solution
$("#myFormId").on('submit', function(e) {
e.preventDefault();
$.ajax({
type: $(this).prop('method'),
url : $(this).prop('action'),
data: $(this).serialize()
}).done(function() {
doYourStuff();
});
});
Problem
I want to call a function after a form is submitted, I see we can do this in jQuery with `.submit(handler function())` but the method description says, the handler method will be executed just before the form is submitted. How can I actually attain this? Should I use `setTimeout` after the form is submitted or is there any other solution for this?