dsjfrkvn818747 2013-12-27 09:19
浏览 101
已采纳

Jquery远程方法无法正常工作

I am new to jquery.. as form validation i am using the following form validation code..

just i added the remote method to check the email existance.. but it always saying the email is "already exist"

Here is the snippet of the code...

<script>
$(document).ready(function(){
    $("#f2").validate({
        debug: false,
        rules: {    
            email: {
                required:true,
                email:true,
                remote:'checkemail.php'
            },
            comments: {
                required:true
            }
        },
        messages:
        {
            email:{
                required:"Please enter valid email",
                remote:"Already Exist"
            }
        }});
});
</script>

Here is the form code..

   <form  name="f2" id="f2" method="post" action="">
       <div>
        <label >Email</label>
        <input type="text" name="email">
     </div>
    </form>

Here is the checkemail.php code..

<?php
    $email=$_GET['email'];
    $query="select email from emails where email='$email'";
    $res=  mysql_query($query);
    $cou=  mysql_num_rows($res);
    if($cou>0)
    {
        echo "true";
    }
    else{
        echo "false";
    }
?>

Update

i missed the db connection.. After putting the db connection in checkemail.php file, the remote method is not showing any message.. and form is submitting without checking the email is already exist why?

why the form behaving like this? Any idea..

Any suggestions are welcome...

  • 写回答

2条回答 默认 最新

  • dongyoucha0645 2013-12-27 11:19
    关注

    Modify you if statement like this if($cou>0) { echo 'false'; } else{ echo 'true'; }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!