我做的login.php與阿賈克斯call..Below是我的AJAX位代碼和login.php中code..while給予有效的用戶名和密碼also..am越來越無效用戶名或密碼信息..完全不瞭解這些代碼行Ajax調用的login.php,響應失敗
$is_ajax = $_REQUEST['is_ajax'];
if(isset($is_ajax) && $is_ajax) // in login.php, Many thanks
$("#login").click(function() {
var action = $("#form1").attr('action');
var form_data = {
username: $("#username").val(),
password: $("#password").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: login.php,
data: form_data,
success: function(response)
{
if(response == 'success')
$("#form1").slideUp('slow', function() {
$("#message").html("<p class='success'>You have logged in successfully!</p>");
});
else
$("#message").html("<p class='error'>Invalid username and/or password.</p>");
}
});
return false;
});
並且這是login.php代碼。
<?PHP
if(isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax']) {
$is_ajax = $_REQUEST['is_ajax'];
$uname = $_POST['username'];
$pword = $_POST['password'];
$uname = htmlspecialchars($uname);
$pword = htmlspecialchars($pword);
$user_name = "root";
$pass_word = "root";
$database = "test";
$server = "127.0.0.1";
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);
$uname = quote_smart($uname, $db_handle);
$pword = quote_smart($pword, $db_handle);
$SQL = "SELECT * FROM login WHERE L1 = $uname AND L2 = md5($pword)";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
echo "success";
}
mysql_close($db_handle);
}
?>
爲什麼'url'參數不帶引號的字符串?現在它是名爲'login'的對象的'php'屬性,這可能不是你想要的。 – apsillers 2012-04-11 13:10:41
先生..我已經把('login.php')代碼,即使我沒有得到成功的消息.. – user1160126 2012-04-11 13:14:50
有人在我之前建議測試一個固定的(已知好的)字符串爲'$ uname'和'$ pword'在PHP文件,而不是從'$ _POST'拉。如果你這樣做,你會得到一個成功的消息嗎? – apsillers 2012-04-11 13:21:00