2012-03-26 151 views
4

嗨我有一个登录系统的jQuery ajax请求。起初,它工作得很好。但经过几次尝试后,它开始显示出负面反应。我检查了萤火虫,它说在我的情况下,回应是“连接”。但是Ajax响应只显示“Not_connected”。我不知道该怎么办:(请帮我Jquery ajax请求显示旧的响应

这是我的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); 
     } 
}); 

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*/ 
    } 
+0

你尝试过手动登录吗?像基于表单的登录?如何试图检查'$ log_result'是否返回有效的响应是真的? – Joseph 2012-03-26 04:21:05

回答

5

看看这些线:Is it possible to cache POST methods in HTTP?

这可能是有头现在使浏览器缓存响应(虽然它是POST)。

而且代替RND =” +的Math.random(),您可以添加写

$.ajax({ 
    type: "POST", 
    cache: false, 
    .. 
2

难道是浏览器缓存? 尝试添加该$ .ajaxSetup({缓存:假});

0

您使用了错误的$就选项检索结果。您应该使用成功选项。只是改变在

complete : function(xhr,data){ 

线

success : function(data){ 

它应该工作。