Jquery验证器与远程的怪异行为 [英] Jquery validator weird behaviour with remote

查看:46
本文介绍了Jquery验证器与远程的怪异行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用jQuery验证器的注册表单:

I have a registration form which is using jQuery validator as:

$('reg_form').validate({
  ignore:"",
  rules : {
    user_name : {
      required :1,
      minlength :8,
      remote :"check_user_name.php"
    },
    password : {
      required :1,
      minlength :8,
    },
    firstname : {
      required :1,
    },
    lastname : {
      required :1,
    },
    email : {
      required :1,
    },
  }
});

它工作得很好,但问题很严重。它永远不会检测用户名是否已经在数据库中。

It worked pretty well but the problem is remote. It never detects if the username is already in the DB.

远程代码如下:

$uname = $_GET["user_name"];

$UserObj = new User();
echo $UserObj->checkUniqueUser($uname);

checkUniqueUser()将检查是否存在具有相同名称的用户,否则将返回false,否则为true。

checkUniqueUser() will check if there is an user with the same name it will return false else true.

我从请求监视中获取了URL

I got the URL from the request watch

http://project.localhost/check_user_name.php?user_name=admin

我热链接了URL,它显示为false ,因为管理员已经存在于数据库中,如果我更改为其他内容它显示为真(当然它不在数据库中)

I hot linked the URL and it says false, since the admin is already there in the DB and if I change to something else it shows true (of course its not there in DB)

有人可以帮助我这个 ?希望我能够说清楚到目前为止我做了什么以及我面临的问题。

Can someone please help me on this ? Hope I was able to make it clear what I have done so far and what issue I am facing.

这是我在User类中的功能。

This is my function which I have in the User class.

public function checkUniqueUser($username){
      $return = true ;
      global $db ;
      $db->query("select iduser from user where 
      user_name = '".$this->cleanInput($username)."'");
      if($db->numRows() > 0 ){
        $return = false ;
      }
      return $return ;
}


推荐答案

因为你想要一个输出,你需要 echo true false ,而不是返回。从技术上讲,返回无处可去。

Since you want an output, you need to echo true or false from your function, not return. Technically, there's nowhere to return.

参见 PHP 返回 PHP echo

public function checkUniqueUser($username){
      $return = true ;
      global $db ;
      $db->query("select iduser from user where 
      user_name = '".$this->cleanInput($username)."'");
      if($db->numRows() > 0 ){
        $return = false ;
      }
      echo $return ;  // echo (output) true or false
}

这篇关于Jquery验证器与远程的怪异行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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