Ajax发送整个页面而不是块

时间:2013-06-18 19:02:01

标签: php jquery ajax login

好的,我正在通过AJAX进行登录页面。出于一些奇怪的原因。下面的AJAX POST页面。

<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/user.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/db.php');
$db = dblogin();

$email = $_POST['email'];
$pass = $_POST['pass'];
$query = "SELECT *  FROM `user` WHERE `email`='".$email."'";

$res = $db->query($query);
if($res->num_rows!='0'){
    if($res->num_rows=='1'){
        $list=$res->fetch_assoc();
    }
}else{
    $list = false;
}
$invalid = <<<_END

<form>
<table>
    <caption>Invalid credentials, please try again.</caption>
    <tr>
        <td>Email:</td><td><input type='email' id='email' name='email' /></td>
    </tr>
    <tr>
        <td>Password:</td><td><input type='password' id='password' name='password' /> </td>
    </tr>
    <tr><td colspan='2' align='center'><input type='button' onclick="login()" value="Log In"></td></tr>
</table>
</form>

_END;


//if the return is false, this executes, which states that the email is not found
//and prompts for a new login
/*if ($list == false){
    $query = "INSERT INTO `failloglog` (`ip`,`email`) VALUES ('".$_SERVER['REMOTE_ADDR']."','".$email."')";
    $db = dblogin();
    $db->query($query);
    echo $invalid;
}*/

//otherwise, it compares the passwords
//else{
    if (pass_compare($pass,$list['password'])){
        cookify($email);
        echo "success";
    }
    else{
        //$query = "INSERT INTO `failloglog` (`ip`,`email`) VALUES ('".$_SERVER['REMOTE_ADDR']."','".$email."')";
        //$db = dblogin();
        //$db->query($query);
        echo $invalid;
    }
//}



?>

我的$invalid给了我一个完全格式化的html页面,页面在这里https://www.dropbox.com/s/hmejactu54891p6/response.txt

而不是只给我console.log(response)

这是jQuery调用。

function login()
{
    var email = $('#email').val();
    var pass = $('#password').val();
    $('#login').html('<img src="img/pleasewait.gif" id="pleasewait"/>');
    $.ajax({
        url: "http://$location/lib/ajax/login.php",
        type: "POST",
        data:{
            email: email,
            pass: pass
        }
    })
    .always(function(response){
        console.log(response);
        if(response=="success"){
            location.href = "http://$location/home.php";
        }
        else{
            $('#login').html(response);
        }
    });
}

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

原来是我用于cookie验证的另一个php文件中的另一个块。

//Prevents not logged in people from getting to inner pages

if (($page != " - Login Page") AND ($page !=" - Confirm Account") AND ($page !=" - User Account Creation") AND (!ISSET($_COOKIE['key'])))
{
    header("Location: http://$location");
}

我将不得不回到以后重新检查我的方法。我计划随着时间的推移更新这个网站/平台。