0
我想添加一個自定義規則來檢查我的jQuery驗證功能的用戶名的唯一性,但它不會返回任何結果。當我提醒msg變量時,它會正確提醒。添加自定義規則jquery驗證檢查唯一的用戶名
這裏是我的代碼:
jQuery(document).ready(function() {
var validator = $("#frmregister").validate({
rules: {
"txtName":"required",
txtuName: {
required:true,
usernameCheck:true // remote check for duplicate username
},
},
messages: {
txtuName:{
required:"Please enter User name",
usernameCheck:"this username is already in use."
},
},
highlight: function(element, errorClass, validClass) {
$(element).removeClass(validClass);
},
errorElement: 'div'
});
});
jQuery.validator.addMethod('usernameCheck', function(txtuName) {
var burl=$("#bseurl").val();
//alert(burl);
var postURL = burl+"home/usernamechk";
//alert(postURL);
var cnt = $("#frmregister").serialize();
jQuery.ajax({
type: "POST",
data: cnt,
url: postURL,
success: function(msg) {
result = (msg== 2) ? true : false;
}
return result;
});
}, '');