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 7080485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:48:04+00:00 2026-05-28T06:48:04+00:00

Here are two functions. function getUserInformation(UserID) { $.post(assets/scripts/chat/get_user_info.php, { UserID: UserID }, function (data)

  • 0

Here are two functions.

function getUserInformation(UserID) {
    $.post("assets/scripts/chat/get_user_info.php", {
        UserID: UserID
    }, function (data) {
        if (data == "error") {
            alertBar('negative', 'There was an error sending the message');
        }
        window.username = data;
    })
}

function CreateChatBox(UserID) {
    if ($('#' + UserID).length == 0) {
        getUserInformation(UserID);
        alert(username);
    }

My issue is, that when the CreateChatBox() function is executed, it has to be clicked twice in order for it to actually work. How ever if I remove the getUserInformation() function from the CreateChatBox() function the CreateChatBox() function executes successfully.

Could anybody help me with this issue? Thanks.

—Edit (extra Detail)—-

When I click a link <a onclick = "CreateChatBox()">Some link</a> nothing happens. But when I click it the second time it does work. If I remove the function getUserInformation() from the CreateChatBox() function the CreateChatBox() function works first time when the link is clicked.

  • 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-05-28T06:48:05+00:00Added an answer on May 28, 2026 at 6:48 am

    It is because the you are not waiting for ajax response to complete. When you click first time the ajax call is made through post and by second click the response is most likely available so you get it. You can see this putting alert inside the success handler.

    function getUserInformation(UserID) {
       $.post("assets/scripts/chat/get_user_info.php", 
       {
             UserID: UserID
       }, 
       function(data){
             if (data == "error") {
                 alertBar('negative','There was an error sending the message');
             }
             window.username = data;
             alert(window.username);
       });
    }
    
    
    function CreateChatBox(UserID) {
       if ($('#'+UserID).length==0) {
            getUserInformation(UserID);
       }
       //alert(username);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions here say animation1 and load1 they work like that: function
I'm struggling with some SQL/php syntax issues here. I'm trying to write two functions.
simonn helped me to code an ordered integer partition function here. He posted two
Here are two questions related to modifying the data source for strongly typed dataset
Here's what I would like to do in pseudocode form. Bind Two Functions to
I have written two functions setSes() and getSes() and here I have written session_start()
I have two functions named ChangeText() & ChangeColor(), the first function called ChangeText who
I'm having some difficulty passing values and arrays between this two functions Here's the
I have two functions, one that creates a table like so: function return_formatted_results(result_no,addy,title,own_comment) {
Need a small hand here im trying to combine two functions to create a

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.