Ced*_*ric 4 javascript php ajax jquery ajax-request
嗨,我有一个登录系统的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);
}
});
Run Code Online (Sandbox Code Playgroud)
AS代码为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*/
}
Run Code Online (Sandbox Code Playgroud)
看看这个帖子:是否可以在HTTP中缓存POST方法?
可能有些标题现在使浏览器缓存响应(尽管它是POST).
也可以添加写入而不是rnd ="+ Math.random()
$.ajax({
type: "POST",
cache: false,
..
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2321 次 |
最近记录: |