我創建了一個jQuery自定義驗證這樣Jquery自定義驗證器 - 檢查一個值是否有效?
var response;
$.validator.addMethod(
"uniqueUserName",
function (value, element) {
$.ajax({
type: "POST",
url: "/umbraco/surface/MemberShipSurface/ValidatePostCode",
data: JSON.stringify({ PostCode: value }),
contentType: "application/json; charset=utf-8",
success: function (msg) {
alert(msg.istrue);
response = msg.istrue;
}
});
return response;
},
"wrong postcode"
);
$("#reg-form").validate({
rules: {
day: {
required: true,
range: [01, 31]
},
PostCode: {
required: true,
number: true,
maxlength: 4,
minlength: 4,
uniqueUserName: true
}
},
errorElement: "span",
submitHandler: function (form) {
}
});
如果從阿賈克斯輸出是事實,就意味着驗證是成功的,我們不需要顯示任何錯誤信息顯示其他錯誤信息。但是現在,我首先從表單上輸入了什麼價值,然後從第二次開始顯示驗證成功。任何人都可以指出我在這裏做錯了嗎?
聲明這個'無功響應=假;' – vel