PHP:通过jquery和php注销不起作用


PHP : Logout by jquery and php not work

我有这样的代码从我的网站注销:-

if($_GET['do'] == 'logout')
{
session_destroy();
setcookie('us_log_in_r','',time()-3600,'/');
$result["process"] = "ok";
} // end action logout

我从另一个PHP文件中的链接注销,例如:-

 <li><a href="#" id="logout" onClick="logout_user_();" ><span>Logout</span></a></li>

和我的jquery:-

// This function to logout
function logout_user_(){
    $.ajax({
      url: "request.php?do=logout",
      type: "POST",
      data: {
          },
      dataType: "json",
      success: function(data){
      if(data.process == "ok"){
        $("#error_reg2").show('fast',function(){
                $("#show_reg2").html("success");            
            });
        $("#error_reg2").fadeOut(5000);
        if ($("#error_reg2").fadeOut(5000)){    
        window.setTimeout(function () {
        location.href = "#one";
    }, 5000)
        }
      }
      else
      {
            $("#error_reg2").show('fast',function(){
            $("#show_reg2").html("Error");          
            });       
      }
      }  
      });
}

我的代码中的错误是当我单击注销链接时,它会向我发送此错误消息:-

data.process 为空?? 为什么

只需在 php 代码末尾添加一行(在 $result["process"] = "ok"; 之后 - } 之前):

echo json_encode($result);

这应该可以做到。