【问题标题】:check whether email exist or not in jquery检查jquery中是否存在电子邮件
【发布时间】:2013-08-17 06:36:35
【问题描述】:

这是我检查电子邮件是否存在的代码...... 我没有得到任何回应。 所以请就这个问题向我提供一些解决方案。还有另一个文件可以检查数据库中的电子邮件..但是 jquery 没有给出任何响应。

这是我的 js 代码..

<html>
<head>
 <?php include("head.inc.php");?>
 <script type="text/javascript">
 //VALIDATE USER EMAIL
    $(document).ready(function(){

    $('#eml').blur(function(){
            $.ajax({
                type:"POST"
                url:check.php,
                data:"username="+$('#eml').val(),
                beforeSend:function(data)
                {   
                    $('#msg').html('chkng..').css("color","green"); 
                },
                success:function(data){

                        if(data =='false')
                        {
                            $('#msg').html("already exist").css("color","red");
                        }
                        else if(data=='true')
                        {
                            $('#msg').html("Valid 6e").css("color","green");
                        }

                }


            });
    });
    });

  </script>
</head>
<body>
<form name="frm" action="check.php" method="post">
<input type="text" name="email" id="eml"/>
<input type="submit" id="ok" name="ok" value="OK"/>
<div id="msg" class=""></div>
</form>
</body>

</html>

检查.php

<?php
        include('conf.inc.php');
        $email=$_POST['email'];
        $q="select u_fname from users where u_email='$email'";
        $rs=mysql_query($q) or die("query");
        if(mysql_num_rows($rs)==0)
        {
            echo 'true'; //allow to register.
        }
        else   
        {
            echo 'false'; //not allow to register.
        }
?>

但我无法获得正确的输出。 没有任何回应。

【问题讨论】:

    标签: email exists


    【解决方案1】:

    尝试使用 return 而不是 echo。

    if(mysql_num_rows($rs)==0)
            {
                return true; //allow to register.
            }
            else   
            {
                return false; //not allow to register.
            }
    

    在js中

    success:function(data){
    
                            if(data === false)
                            {
                                $('#msg').html("already exist").css("color","red");
                            }
                            else if(data === true)
                            {
                                $('#msg').html("Valid 6e").css("color","green");
                            }
    }
    

    为什么 === 而不是 == 在这里阅读 http://www.w3schools.com/js/js_comparisons.asp

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-15
      • 2013-01-05
      • 2015-12-09
      • 1970-01-01
      • 2013-06-08
      • 2022-01-20
      • 2016-04-06
      • 1970-01-01
      相关资源
      最近更新 更多