這裏有一個鏈接,我看到,但仍然感到困惑了爲他們提供的答案: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