Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:50:51+00:00 2026-06-13T20:50:51+00:00

So im trying to figure out whats wrong here! Im using Ajax to log

  • 0

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);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:50:52+00:00Added an answer on June 13, 2026 at 8:50 pm

    Your description is that you are clicking a link. Chances are the page is refreshing before the AJAX is complete.

    Try:

    $("#unlog").live("click", function() {
        req_content("top", "user", "logout", "goodbye");
        /* prevent browser default event on element such as link being followed, or form being submmitted*/
        return false;
    });
    

    Instead of sending back the normal content you can also return from your php:

     print_r( $_SESSION);
    

    As response for AJAX and see what gets sent back. It will get put into your page where the expected content would go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out what I'm doing wrong here. Using autocomplete I'm getting
I'm trying to figure out what I'm doing wrong. Here is a very simple
I'm trying to figure out what's wrong with my mysqli code below. The data
So I've been trying to figure out what is wrong with my if-condition, but
I am trying to figure out what is going on. Here is our setup:
I am trying to figure out how to create multiple objects when using Dependency
I've spent several days trying to figure out what is wrong with my android
I'm trying to figure out how to grab DOM elements from a webpage. Here
I'm new to AJAX and trying to figure out how to do a JSONP
hope someone can figure out what I'm doing wrong here. The task seems quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.