您好我有一个登录系统的 jQuery ajax 请求。起初,它工作得非常好。但经过几次尝试,它才开始出现负面反应。我检查了萤火虫,它说在我的情况下响应是“已连接”。但是 ajax 响应只显示“Not_connected”。我不知道该怎么办:(。请帮助我。
这是我的jQuery代码:
var data_str = "username="+usrn+"&password="+pwd;
$.ajax({
type: "POST",
url: "index.php?rnd=" + Math.random(),
data : data_str,
complete : function(xhr,data){
if(data == 'connected'){window.location.href = 'admin.php';}
else if(data = 'not_connected'){ error_gen.html('Invalid username or password'); }
alert(data);
}
});
至于 PHP 代码:
$log_result = $u_obj->login_user();
if($log_result == true)/*user is connected*/
{
echo 'connected';
exit;/*stoping the script after sending the result*/
}
elseif($log_result == false)/*error while logging in*/
{
echo 'not_connected';
exit;/*stoping the script after sending the result*/
}