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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:53:16+00:00 2026-06-16T07:53:16+00:00

I am looking for something like this function someFunc() { callAjaxfunc(); //may have multiple

  • 0

I am looking for something like this

function someFunc() {

callAjaxfunc(); //may have multiple ajax calls in this function
someWait(); // some code which waits until async calls complete
console.log('Pass2');

}

function callAjaxfunc() {
  //All ajax calls called here
  console.log('Pass1');

}

What I have tried?

1
Jquery.when()

tried using it..it works fine. But not the way I want. $.when will wait but the code next to $.when() runs with out waiting. The code inside do callback only runs after ajax calls

2.
setTimeOut() with a global flag

I was so confident this will work. I tried like following.

GlobalFlag = false;

function someFunc()     
    callAjaxfunc(); //may have multiple ajax calls in this function
    setTimeOut(waitFunc, 100); // some  which waits until async calls complete
    console.log('Pass2');
}

function callAjaxfunc() {
    //All ajax calls called here
    onAjaxSuccess: function() {
        GlobalFlag = true;
    };
    console.log('Pass1');    
}

function waitFunc() {
    if (!GlobalFlag) {
        setTimeOut(waitFunc, 100);
    }
}​

Still not able to get wanted result. Am I doing something wrong here? This is not the way?

Result I wanted should come like this

Pass1
Pass2

Not able to make any fiddle as it needs AJAX calls

EDIT: As many were suggesting callbacks..i know about them..but still the code next to somewait() will get executed…I want browser to completely stop executing code next to somewait() until the ajax call..Also it may be a bad practice but worth to know and try if possible…

  • 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-16T07:53:17+00:00Added an answer on June 16, 2026 at 7:53 am

    Use callbacks. Something like this should work based on your sample code.

    function someFunc() {
    
    callAjaxfunc(function() {
        console.log('Pass2');
    });
    
    }
    
    function callAjaxfunc(callback) {
        //All ajax calls called here
        onAjaxSuccess: function() {
            callback();
        };
        console.log('Pass1');    
    }
    

    This will print Pass1 immediately (assuming ajax request takes atleast a few microseconds), then print Pass2 when the onAjaxSuccess is executed.

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

Sidebar

Related Questions

I have a setup looking something like this: def foo_decorator(function): @wraps(function) def decorator(*args, **kwargs):
I am looking to scroll the page to a particular location.Something like this: function
I'm looking to create something like in this image. Each block would have an
I have a select looking something like this: <select id=address> <option noodd=1-9 noeven=2-6>Address Name
I'm looking at JQuery Tiny Pub/Sub, which looks something like this: (function($){ var o
I'm looking for something like this: SELECT german_subsidiaries.*, customers.* FROM german_subsidiaries INNER JOIN customers
How can a validation exclude a regexp? I'm looking for something like this: validates_format_of
My whole purpose of this is to get something looking like this: I want
I'm looking for a way to do something like this: var db = new
Looking for a non-JS solution. Say I had something like this: <ul> <li> <form>

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.