为什么我会得到答案“不”?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