这里有一个链接,我看到,但仍然感到困惑了为他们提供的答案:jQuery Ajax returns the whole pagejQuery的返回整版阿贾克斯
我的情况是类似的东西。
我有一个index.php,它需要一个弹出式登录表单,它试图将这个登录信息提交给另一个名为login_check.php的php的ajax调用。
这是我的index.php:
var dataString = 'email='+ email.val() + '&password=' + password.val();
$.ajax({
type: "POST",
url: "login_check.php",
data: dataString,
cache: false,
error: function (request, status, error) {
alert("An error occured while trying to complete your request: " + error);
},
success: function(data)
{
alert(data);
}
});
这是在我的login_check.php:
session_start();
//input from login form
$myemail = htmlspecialchars(trim($_POST['email']));
$mypassword = htmlspecialchars(trim($_POST['password']));
//selecting from database to check user account
$sql="SELECT * FROM user WHERE email='$myemail' and password='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$count=mysql_num_rows($result);
//If result matched $myemail and $mypassword, table row must be 1 row
if($count==1)
{
echo 'true';
session_register("myemail");
$_SESSION['login_user']=$myemail;
}
else if($count==0)
{
echo 'false';
}
而且警告框的输出页面的完整HTML我我目前在,即index.php。
我不知道为什么。 ):
尝试在发送GET参数时将Ajax调用类型更改为GET。您还需要更改您的PHP代码以使用'$ _GET'变量。 – Lix 2012-03-17 13:59:32
请尝试将问题缩小到客户端或服务器端。对于客户端,您可以使用chrome开发人员工具检查传出的ajax调用。而对于服务器端,你可以发送自己的电子邮件包含整个'$ _REQUEST'数组...... – Lix 2012-03-17 14:06:05
jquery看起来不错,所以我猜这个问题是PHP页面返回一个完全呈现的响应。 – 2012-03-17 14:31:57