When a user submits a form I want ajax to check if the email address exists using the following
$.post("checkemail.php", {email: email})
Depending on the value I will choose to submit or not (preventdefault)
However the form is submitting before returning the value.
I have tried the following:
$.when($.post("inc/checkemail.php", {email: email})).done(function(result) {
// code here
}
However I can’t seem to get this right. What am I doing wrong?
Thanks for any help in advance, you guys are always great!
Stopping the default behavior should always happen regardless of what the post returns. Only on ‘done’ should you decide to submit the form:
edit: Also, note that $.post returns a type of deferred object, so the $.when call is unnecessary.