爲什麼我會得到答案「不」?jquery ajax表單函數(數據)
jQuery的將數據發送到PHP查詢
$j.post("logincheck.php",{
username:$j('#username').attr('value'),
password:$j('#password').attr('value'),
rand:Math.random() } ,
function(data) {
if(data=='yes') {alert('yes');}
else {alert('no');}
}
);
這裏是PHP查詢
if(isset($_POST['username'])):
$username = $_POST['username'];
$password = $_POST['password'];
$posts = mysql_query("SELECT * FROM users WHERE username='$username'");
$no_rows = mysql_num_rows($posts);
while($row = mysql_fetch_array($posts)):
print 'yes';
endwhile;
else:
print 'no';
//header('location: index.php');
endif;
endif;
php代碼是否完整或是否存在? 您是否試圖查看數據對象以查看它返回的信息類型? PS 爲什麼dont'you使用.VAL()方法,而不是.attr( '值')? – mamoo 2010-04-15 12:30:07
就像旁註一樣,我不會通過GET請求發送密碼值,除非它是完全不可避免的。 – 2010-04-15 12:31:02
您是否嘗試提醒數據?您是否從服務器端迴應yes? – ant 2010-04-15 12:32:18