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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:56:21+00:00 2026-05-12T16:56:21+00:00

I have an if statement: if(authenticate_session(secret_password12345)){ alert(You are authenticated); }else{ alert(Intruder alert!); } and

  • 0

I have an if statement:

    if(authenticate_session("secret_password12345")){
        alert("You are authenticated");
    }else{
        alert("Intruder alert!");
    }

and the javascript authenticate function, which makes an jQuery POST AJAX call to the server to do the actual authentication, and returns true or false:

function authenticate_session(session_id){
 $.post("/auth.php",
    { action: "authenticate_session", login_id: session_id },
    function(data){
        if(data == "denied"){
            alert("denied");
            return false;
        }else if(data == "accepted"){
        alert("accepted");
            return true;
        }
    },
"text");
}

However, when the if statement invokes the athentication function, it doesn’t wait for the AJAX to complete, and always executes the ‘else’. If I add ‘return true;’ into the first line of the authentication function, before the ajax, the if statement performs as expected => alert(“You are authenticated”).

I know that the server side is performing properly, as the alert(“denied”) and alert(“accepted”) are being called as expected (but interestingly, after the if statement alerts).

How can I make my if statement wait until the authentication function has completed?

Thanks!

  • 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-12T16:56:21+00:00Added an answer on May 12, 2026 at 4:56 pm

    It’s not waiting because it’s an asynchronous request by default. Set the async option to false for it to be synchronous. From the docs:

    By default, all requests are sent
    asynchronous (i.e. this is set to true
    by default). If you need synchronous
    requests, set this option to false.
    Note that synchronous requests may
    temporarily lock the browser,
    disabling any actions while the
    request is active.

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

Sidebar

Related Questions

I have this statement in my jQuery file: $.get(homeTemplates/randomVids.php, function(data){$(#hVid).html(data);}); Where the contents of
I currently have this statement in my SQL View (SQL Server 2008 R2) which
I currently have a statement which reads if(Arrays.asList(results).contains(Word)); and I want to add at
I have this statement which is the wrong way to do it but how
I have a statement being used with PDO which is as follows: $stmt =
I have this statement in application.html.erb: <%= yield(:javascript) %> and I have the following
In Python I have this statement: blog_ids = [c.blog_id for c in connections] Which
I have select statement which shows selected items in datagrid. cmdSel.CommandText = select id,Name,TypeID,StatusID
if i have statement: $a = 1; $b = 2; $c = 3; if($a
I have this statement in my c program and I want to optimize. By

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.