2015-12-30 102 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

沒有區別:( –