JQuery 远程验证未显示错误
JQuery Remote Validation not displaying Error
我正在使用 JQuery 验证插件,除了对用户名的远程验证是唯一的之外,它工作得很好。
脚本是 returning "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";
}
}
?>
数据视图 class 所做的只是 return 一个数字。
任何帮助或指导都会很棒!
试试这个:
//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"
}
}
});
})
我阅读了其他几个论坛,发现我需要回显结果并将 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";
}
}
echo $return;
?>
我正在使用 JQuery 验证插件,除了对用户名的远程验证是唯一的之外,它工作得很好。
脚本是 returning "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";
}
}
?>
数据视图 class 所做的只是 return 一个数字。
任何帮助或指导都会很棒!
试试这个:
//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"
}
}
});
})
我阅读了其他几个论坛,发现我需要回显结果并将 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";
}
}
echo $return;
?>