我添加了此验证器以输入我的注册表单:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="button-wrapper">
<a class="flip top-button" href="#first-div" target="" data-toggle="">Div1</a>
<a class="flip top-button" href="#second-div" target="" data-toggle="">Div2</a>
</div>
<div class="content" id="first-div">
<h1>Im the first DIV</h1>
</div>
<div class="content" id="second-div">
<h1>Im the second DIV</h1>
</div>
在这里我为我的输入激活方法:
jQuery.validator.addMethod("checkEmailDuplicate", function (value, element) {
var returnedResponse = true;
jQuery.ajax({
type: 'GET',
url: '/user/register/verify-email.ajax',
data: {
'email': value
},
dataType:'json',
async: false,
success:function(response) {
if (response.duplicate == true) {
returnedResponse = false;
}
},
error:function(err) {
console.log('Error ' + err);
}
});
return returnedResponse;
});
我希望此验证程序仅在returnedResponse为true时显示消息。仅当满足Ajax请求中的条件时,returnedResponse才为false。问题是无论我在输入中输入什么内容,都会显示该方法的消息。