if (data == 'success') does not evaluate the result obtained from external php, it returns sucess but the page remains frozen. Thank you

0

   

             

        <label>
            <span>Email</span>
            <input type="email" placeholder="[email protected]" id="email">
        </label>
        <label>
            <span>Password</span>
            <input type="password" placeholder="password" id="password">
        </label>
        <label>
            <button id="login">Login</button>
        </label>

    </div>
</div>

<script type="text/javascript" src="js/jquery.js"></script>

------------------- auth.php ---------------------

$(document).ready(function(){
    var url="http://miweb.com/auth.php";
    $("#login").click(function(){       
        var email=$("#email").val();
        var password=$("#password").val();
        var dataString="email="+email+"&password="+password+"&login=";
        if($.trim(email).length>0 & $.trim(password).length>0)
        {
            $.ajax({
                type: "POST",
                url: url,               
                data: dataString,
                crossDomain: true,
                cache: false,
                success: function(data){
                    if(data.login=="success")
                    {
                        window.location.href = "index.html";
                    }                   
                    else if(data.login="failed")
                    {
                        alert('Login error!!');
                        $("#login").html('Login');
                    }
                }
            });
        }return false;

    });


})

--------------------------------php---------------------
if(isset($_POST['login']))
{
    $email=mysql_real_escape_string(htmlspecialchars(trim($_POST['email'])));
    $password=mysql_real_escape_string(htmlspecialchars(trim($_POST['password'])));
    $login=mysql_num_rows(mysql_query("select * from 'users' where 'email'='$email' and 'password'='$password'"));
    if($login!=0)
        { echo "success"; }
    else{ echo "failed"; }
}
    
asked by Jose Alvarez 19.06.2017 в 22:56
source

0 answers