doutangdan3588 2011-07-27 10:43
浏览 24

JQuery Email已经注册

Can any body help me.. i have some problem in jquery email validation, i want to check that this email has already registered or not.. i have tried but my code is not working (i.e did not show error message)

here is the script

$(document).ready(function(){   
    $("add_form").validate( {
       rules: {  
           email: {
        required: true,
        email: true,
            remote: "emails.php"
    },
 },
 messages: {
         email:   {
    remote: jQuery.format("{0} is already in use")
        }
 },
 });

and emails.php file code here

 <?php
$request = trim(strtolower($_REQUEST['email']));

require 'db.inc.php';
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));


$query = 'SELECT email FROM Users WHERE email="'.$request.'"';
$result = mysql_query($query, $db) or die(mysql_error());
$valid = 'true';
if (mysql_num_rows($result)>0) 
{
    $valid = '"Thats already taken."';
}
echo $valid;

?>
  • 写回答

1条回答 默认 最新

  • douwen3198 2011-08-05 10:14
    关注

    According to the docs, the response of remote validation is a JSON-encoded boolean, not a JSON-encoded string.

    You have "true" or "false", which will become "\"true\"" or "\"false\"" through json_encode(), which is wrong. Actual true or false will become "true" or "false", which is correct.

    Setting the response content type to JSON might also be a good idea:

    header('Content-type: application/json');

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决