I basically copied an entire form submission code I had up and running on a Website and pasted it into a blank file in order to modify its contents and save some time. IN THEORY, then, if the original file stopped normal form submission from opening up the Action target file while still completing the submission, this one should do the same.
However, I can't get it to work like it did. I can't stop the submission from leaving the current window.
Can anyone please point me toward what I'm doing wrong?
(Aside from the PHP code I'm using the jQuery Validation Plugin, same as I was using in the previous form that worked as expected.)
Form HTML code:
<form id="form" class="appintro" method="post" action="manageform.php" enctype="multipart/form-data"></form>
JS
$.validator.setDefaults({
submitHandler: function() { //<-- Handler called by jQuery Validation once form is validated
$('.msg.sending').fadeIn(200);
$.ajax({
type: 'POST',
url: form.attr('action'),
data: form.serialize(),
success: function() {
alert('Success')
},
error: function() {
alert('Failure')
}
});
return false; //<-- This should stop the normal submission...
}
});
I've also already tried calling the AJAX outside of the validator
code, i.e. using $("form").submit(function(event)...
, etc. Also tried setting data
to form.serializeArray()
, as recommended in some other SO post... Nothing does it.
Thanks in advance for your help!
EDIT 1
I've set up this jsFiddle to test it out in a simpler version. No matter what I place in AJAX's url
, I get an error. If I fill the form's action
, then I can't catch the submission.