jQuery远程验证不显示错误 [英] JQuery Remote Validation not displaying Error

查看:60
本文介绍了jQuery远程验证不显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JQuery Validation插件,该插件除了对用户名进行远程验证以外,还可以很好地发挥作用.

I am using the JQuery Validation plugin which is working great apart from the remote validation on a username to be unique.

该脚本返回的是"true"或"false",您将从下面的代码中看到.但是我不确定为什么它没有显示错误...值得一提的是显示了User上的其他错误.

The script is returning "true" or "false" which you will see from the below code. But I am not sure why it isn't displaying an error... It's worth mentioning the other errors on User are displayed.

jQuery验证规则:

Jquery Validation Rules:

User: {
                required: true,
                minlength: 6,
                remote:{
                    url: 'scripts/userCheck.php',
                    type: "post"
                }
            }

JQuery验证消息:

JQuery Validation Messages:

User: {
                    required: "Please Enter a Username",
                    minlength: "Username must be more than 6 characters in Length",
                    remote: "User already exists"
                }

userCheck.php:

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类所做的只是返回一个数字.

All the dataview class does is return a number.

任何帮助或指导都会很棒!

Any help or guidence would be great!

推荐答案

我阅读了其他一些论坛,发现我需要回显结果并将userCheck.php更改为以下内容:

I Read a few other forums and found that I needed to echo the result and changed the userCheck.php to the below:

<?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远程验证不显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆