I have a login page, I want to check if the given email exists in the database with an AJAX request. If the email is not found, I want to stop the process so the form won't be submitted. check.php
returns a string if the email is not found (otherwise, it doesn't return anything.) I call the preventDefault();
method when the check.php
returns a string, but it doesn't stop the form from submitting data. How can I stop the submission of the form when the email doesn't exist? It should be something easy, but I can't figure it out.
$("form").submit(function(event) {
$.ajax({
url: "check.php",
cache: false,
type: "POST",
data: {email: $(".email").val()},
dataType: "text",
success: function(info) {
$(".info").text(info);
},
complete: function() {
if (!$(".info").text() == "") {
event.preventDefault();
}
}
});
});