So im trying to figure out whats wrong here!
Im using Ajax to log users in and out and refresh some part of the document as they do. Everything is working fine but when i log out i have to click my link twice in order to see the changes.
It look like im destroying the session after all the instruction have been completed.
Here is how it work (or almost!)
The document html/php
<div id="top">
<?php
$top = new top();
$top->display();
?>
</div>
So im just calling a class that make the content of the top of the document and this is working fine.
In the top when your logged in you have the logout option and the following jquery/ajax call
$("#unlog").live("click",function(){
req_content("top","user","logout","goodbye");
});
So when i click logout i run req_content() function and this is all working well
Now when i click it y run my kinda ajax_query responder
if($ajax_action=='logout'){
unset($_SESSION['user']);
session_destroy();
require('class.php');
$top=new top();
$top->display();
}
Now what happend is that i run the query but the page kinda refresh before the session var is actualy destroyed. If i click it a second time it is working as expected becuse the session is already destroyed.
Anyone can explain this? The process is the same with my login and it is working fine.
The req_content() function
function req_content(box,user,action,query) {
var xhr = getXMLHttpRequest();
document.getElementById(box).innerHTML="<img src='img/load.gif' alt'Loading....'>";
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
document.getElementById(box).innerHTML=xhr.responseText;
}
};
var sVar1 = encodeURIComponent(box); /* Endroit ou on demande le contenu*/
var sVar2 = encodeURIComponent(user); /* Qui demande le contenu(facultatif)*/
var sVar3 = encodeURIComponent(action); /* Quel action veut-on effectuer*/
var sVar4 = encodeURIComponent(query); /* La requete pour efectuer l'action*/
xhr.open("GET", "ajax_http.php?box=" + sVar1 + "&user=" + sVar2 + "&action=" + sVar3 +"&query=" + sVar4, true);
xhr.send(null);
}