2015-12-30 100 views
1

我正在使用JQuery验证插件,它对远程验证的用户名是独一无二的。JQuery远程验证不显示错误

该脚本返回“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"; 
    } 
} 
?> 

所有的数据视图类确实是返回一个数字。

任何帮助或指导将是伟大的!

+0

哪里是'data'发布在远程? – AnkiiG

+0

虽然看着萤火虫我可以看到在请求正文用户正在传递,而不需要数据部分? –

回答

0

我读了几其他论坛,发现我需要呼应的结果,改变了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; 
?> 
0

试试这个:

//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" 

       } 
      } 
     }); 
}) 
+0

没有区别:( –