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

  • Home
  • SEARCH
  • 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 7775507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:38:55+00:00 2026-06-01T17:38:55+00:00

I have this code that loads on document.ready and it checks if the user

  • 0

I have this code that loads on document.ready and it checks if the user is logged in or not:

//Checking if the user is logged in or not
$(function(){
$.getJSON("inc/API.php", {command : "getUserName"},
    function(result){
        if(result==null){
            $("#divGreeting").html("Hello, guest!");
        }
        else {
            $("#divGreeting").html("Hello, "+result+"!");
            $("#divHeader").html("Hello, "+result+"! <a href='javascript:logout()'>Logout</a>");
        }
    });

});

If he’s not – it says “Hello, guest”; if he is – it says “Hello, username“, where username is the result in this function. What I need, is to make the username in this part: $("#divGreeting").html("Hello, "+result+"!"); to be a link, which leads to another page with userID, which I don’t have. Like this: $("#divGreeting").html("Hello, <a href='userpage.html?userid="+HAVE TO GET THE ID HERE+"'>"+result+"</a>!");

I tried to use this function (it does get the:

function getUserID(){
    $.getJSON("inc/API.php",
    {
        command : "getUserID"
    },
    function(result){
        return result;
    });
}

and to call it like that: $("#divGreeting").html("Hello, <a href='userpage.html?userid="+getUserID()+"'>"+result+"</a>!");, but that didn’t work, I didn’t get any result, except for undefined (I understand it has something to do with asynchronous AJAX).

This is the content of API.php:

case "getUserID":
    echo getUserID();
    break;

it call’s for function getUserID() from file BusinessLogic.php, which has this function:

function getUserID()
{
$arr = select("SELECT userID FROM users WHERE username='".$_SESSION["username"]."'");
return $arr[0]["userID"];
}

I’ve been told that I have to use callbacks, but I have no idea how to do that, how to write this callback. I’m lost here…

Some help, please?

  • 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-01T17:38:57+00:00Added an answer on June 1, 2026 at 5:38 pm
    $.getJSON("inc/API.php", {command : "getUserID"}, function(result){
        var id = result;
        $.getJSON("inc/API.php", {command : "getUserName"}, function(result){
             $("#divGreeting").html("Hello, "+result+"!");
             $("#divHeader").html("Hello, <a href='userpage.html?userid="+id+"'>"+result+"</a>!");
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: $(document).ready(function(){ $(.links a).click(function(e){ var toLoad = products.html # + this.id;
i have this code $(document).ready(function () { $('a').click(function(e) { e.preventDefault(); url = $(this).attr('href'); $(body).load(href);
I have this code that performs an ajax call and loads the results into
I have these set of code from a helper: $(document).ready(function(expanded) { var listItems =
I have two functions that loads on document ready. They work fine when they
Right now, I have this on my page: <script type=text/javascript> $(document).ready(function () { var
this code: $(document).ready(function() { $('body').click(function(evt) { if(evt.target.nodeName === 'A' && $(evt.target).hasClass('cross-link')) { $('a[href=#2]').trigger('click'); }
I have this code that works in a unit test but doesn't work when
I have this code that I want to make point-free; (\k t -> chr
I have this code that fetches some text from a page using BeautifulSoup soup=

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.