Is it possible to submit a form using form.submit() and making the submission go through ajax instead of redirecting the url?
Here's what I have:
var form = document.form
form.onsubmit = function() {
var params = {
type: "POST",
url: form.action
}
$.ajax(params).then(function(resp) {
// handle response
})
}
form.submit()
However the submission does not hit the callback and instead redirects the browser to the form.action url. How can I avoid the redirection and submit via ajax?
form.submit()if you want to handle it manually?onsubmit="return false"? on form tag properties