php – JQuery远程验证不显示错误
作者:互联网
参见英文答案 > jQuery Validate remote method usage to check if username already exists 2个
我正在使用JQuery Validation插件,除了用户名上的远程验证之外,它是独一无二的.
脚本返回“true”或“false”,您将从下面的代码中看到.但我不确定为什么它没有显示错误…值得一提的是显示用户的其他错误.
Jquery验证规则:
User: {
required: true,
minlength: 6,
remote:{
url: 'scripts/userCheck.php',
type: "post"
}
}
JQuery验证消息:
User: {
required: "Please Enter a Username",
minlength: "Username must be more than 6 characters in Length",
remote: "User already exists"
}
userCheck.php:
<?php
/**
* Created by PhpStorm.
* User: nathanenglish5
* Date: 30/12/2015
* Time: 09:05
*/
include_once "init.php";
include_once "../resources/signup.class.php";
$signup = new signup($DB_con);
$return = "false";
$count = 0;
if (isset($_Post['User'])) {
$uid = $_Post['User'];
$sql = "SELECT COUNT(username) FROM username WHERE username = '$uid'";
$count = $signup->dataview($sql);
if($signup->dataview($sql)==0){
$return = "true";
}
}
?>
所有dataview类都返回一个数字.
任何帮助或指导都会很棒!
解决方法:
尝试这个:
//Our validation script will go here.
$(document).ready(function(){
//validation implementation will go here.
$("#form_id").validate({
rules: {
user: {
required: true,
minlength: 6,
},
remote: {
url: 'scripts/userCheck.php',
type: "post"
}
},
messages: {
user: {
required: "Please Enter a Username",
minlength: "Username must be more than 6 characters in Length",
},
remote: {
remote: "User already exists"
}
}
});
})
标签:php,jquery,jquery-validate 来源: https://codeday.me/bug/20191003/1847778.html