規則
clientName:{
required:true,
checkName:true
}
messages
clientName:{
required:"客戶端不能爲空",
checkName:"該名稱已存在"
},
添自定義ajax
$.validator.addMethod( //規則的名稱 "checkName", //校驗的函數 function (value,element,params){ //定義一個標誌符true或者false都沒有關係只是定義 var flag=true; //value:輸入的內容 //element:被校驗的元素對象 //params:規則對應的參數值 $.ajax({ "async":false ,//是否異步 "url":"${base}/oauthClientDetails/Seesecret", "data":{"clientId":value}, "type":"GET", "dataType":"json", "success":function(data){ console.log(data); flag=data; } }); //返回false表示校驗器不經過 return !flag; });