0

我的 ajax 和 php 代码又遇到了麻烦。该语句我一直未能获得成功的语句。这是我的代码

            <script type="text/javascript">
            $(document).ready(function(){
                $("#login_a").click(function(){
                    $("#shadow").fadeIn("normal");
                     $("#login_form").fadeIn("normal");
                     $("#Username").focus();
                });
                $("#cancel_hide").click(function(){
                    $("#login_form").fadeOut("normal");
                    $("#shadow").fadeOut();
               });
               $("#login").click(function(){

                    username=$("#Username").val();
                    password=$("#Password").val();
                     $.ajax({
                        type: "POST",
                        url: "1.php",
                        data: "Username="+username+"&Password="+password,
                        success: function(html){
                          if(html=='1')
                          {               $("#login_form").fadeOut("normal");
                            $("#shadow").fadeOut("normal");
                          document.location = '/reward/home.php';
                          }
                          else
                          {
                                $("#add_err").html("Wrong Username or Password");
                          }
                        },
                        beforeSend:function()
                        {
                             $("#add_err").html("Loading...")
                        }
                    });
                     return false;
                });
            });
            </script>
         </head>
         <body>
            <div id="login_form">

                    <form action="" id="loginForm">
                        <label>User Name:</label>
                        <input type="text" id="Username" name="Username" />
                        <label>Password:</label>
                        <input type="password" id="Password" name="Password" />
                        <label></label><br/>
                        <input type="submit" id="login" value="Login" />
                        <input type="button" id="cancel_hide" value="Cancel" />
                    </form>
                <div class="err" id="add_err" style="color:#FF0000; font-weight:bold"></div>
                </div> 

我的 SQL 连接都位于我的函数文件中。当我绕过ajax并从表单转到dologin.php时,它会回显s“1”,这应该意味着成功并让我登录。
这是我的dologin.php文件......

            $root = $_SERVER['DOCUMENT_ROOT'];
            include($root."/reward/function.php");


                $Username = mysql_real_escape_string($_REQUEST['Username']);
                $Password = mysql_real_escape_string($_REQUEST['Password']);
                $Password2 = ($Password);
                $sql = mysql_query("SELECT * FROM PERSON WHERE Username = '$Username' AND Password = '$Password2'") or die(mysql_error());
                $sql2 = mysql_query("SELECT * FROM PERSON WHERE Username = '$Username'");
                if(mysql_num_rows($sql)==1){
                    echo "1";
                    while($info = mysql_fetch_assoc($sql)){
                        $FName = $info['FName'];
                        $_SESSION['FName24'] = $FName;
                    }
                }
                elseif (mysql_num_rows($sql)>1){
                    echo "2";
                }
                    elseif (mysql_num_rows($sql)==0){
                    echo "0";
                } ?>
4

1 回答 1

0

When you are using Google Chrome, hit F12 and go to tab Console. from there you could see the errors of your pages.

Put this code here

             $.ajax({
                    type: "POST",
                    url: "1.php",
                    data: "Username="+username+"&Password="+password,
                    success: function(html){
                      console.log(html)
                      if(html=='1')
                      {               $("#login_form").fadeOut("normal");
                        $("#shadow").fadeOut("normal");
                      document.location = '/reward/home.php';
                      }
                      else
                      {
                            $("#add_err").html("Wrong Username or Password");
                      }
                    },
                    beforeSend:function()
                    {
                         $("#add_err").html("Loading...")
                    }
                });
                 return false;
            });

You should see your error

于 2012-04-06T14:04:43.683 回答