[英]Issue using remote method in jquery validation
要使用remote
的默認方法,遠程頁面必須使用字符串值"true"
或"false"
響應。
有效 ( 成功 )必須是:
echo "true";
無效 ( 失敗 ):
echo "false"; // this can be any false. eg: 0 , "" , NULL.
響應將被評估為JSON。
要應用錯誤消息(遠程響應無效的默認值(“false”),請將輸入名稱添加到驗證器選項messages
對象中,如此。
rules:{
username:{
remote: "check-username.php"
}
},
messages:{
username:{
remote: jQuery.format('{0} is already in use, please choose a different name')
}
}
你不需要JSON。 你可以放任何文字。 例如,你可以
echo "success";
通過驗證,並輸入驗證消息,如:
echo "Username already exists.";
驗證失敗。
在你的回調中做這樣的事情:
remote: {
url: "check-username.php" ,
type: "post" ,
data: {
username: function() {
return $("#username").val();
},
complete: function(data){
if( data.responseText != "success" ) {
alert(data.responseText);
//handle failed validation
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.