在以下代码中,无论checkEMailExists
是返回true
还是false
,都会生成错误消息。我究竟做错了什么? ajax
来电正常。
$().ready(function () {
$.validator.addMethod("checkEmailExists",
function (value, element) {
$.when(checkEmail()).done(function (response) {
console.log((response == 1 ? "true" : "false"));
return response == 1; // returns true if response is 1, false otherwise
});
},
"This email address is registered"
);
$("#loginform").validate({
rules: {
email: {
required: true,
checkEmailExists: true
}
},
messages: {
email: {
required: "Please enter a valid email address",
checkEmailExists: "This email address is already registered"
}}
});
function checkEmail() {
var email = $("#email").val();
var data = {email: email};
return $.ajax({
type: "POST",
url: "http://localhost/check_email/check_email.php",
data: data
});
}