I’m catching clicks on submit button of a form. I do event.preventDefault() to disable default browser action so I’m able to do my stuff after clicking to button. I this case I do AJAX call to server. By response from the server I want to choose if continue with form submission or do something else.
$inviteSubmitForm.find('input[name="accept"]').click(function(e){
e.preventDefault();
$.ajax({
...
success : function(data) {
if (data.something) {
...
} else {
...
}
}
});
});
Problem with this is, that I’m unable to cast default action of clicked button, cos logic is in AJAX callback. So return true just end callback function – I cannot use this simple trick. Also moving e.preventDefault() is no-go, cos form gets submitted immediately.
Any ideas?
trigger to submit the form: