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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:13:33+00:00 2026-06-14T23:13:33+00:00

I am making an ajax call to the server. The code I need to

  • 0

I am making an ajax call to the server. The code I need to run can be divided into 3 groups.

  1. Code that needs to run before the ajax call ins made (preparing the json object going to the server)
  2. Code that needs to be run after the ajax call has returned (uses what was sent back from the server)
  3. Code that needs to be run between the time the user presses a button and the time everything is done. This code does not need the returned json object.

It would be ideal to run the code in group 3 after making the ajax call and before the results are back to gain the best user experience and performance.

Can this be done?

How?

  • 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-14T23:13:35+00:00Added an answer on June 14, 2026 at 11:13 pm

    Very simply:

    function someFunction() {
        //1. code that needs to run before ajax
        $.ajax({...}).done(function () {
            //2. code that needs to be run after the ajax call has returned
        });
        //3. code that needs to be run between the time the user presses
        //   a button and the time everything is done.
    }
    

    This works because JavaScript is synchronous in execution (unless workers are being used, but that’s unrelated to this particular issue). The first bit of code will run, then the ajax call will tell the browser to start an XHR request, but someFunction hasn’t finished, so it will continue to execute synchronously.

    Once someFunction is done, the control flow will be opened up to any asynchronous events that occur, eventually leading to the done callback.

    To be fair, asynchronous event-oriented programming is not easy for most people to wrap their heads around. It’s easy to lose track of what code is supposed to occur at what time.

    Here’s an easily executable example of how asynchronous behavior works:

    (function () {
        alert(1);
        setTimeout(function () {
            alert(2);
        }, 0); //note the 0ms delay
        alert(3);
    }());
    

    The order of alerts will be 1, 3, 2. setTimeout will not call its callback synchronously as it relies on waiting for the specified amount of time to elapse, so even if no time is supposed to elapse, it still has to wait for the current function to finish before it can continue.

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

Sidebar

Related Questions

After making ajax call using Jquery to the vb.net server side code, I need
I am making an ajax call to a server as soon as i enter
I'm making AJAX calls to a server that sometimes return unparseable JSON. The server
When making an AJAX call from the client, the server responds with Hebrew text.
I'm making crossdomain call with code: $.ajax({ type: GET, url: data.Url, mimeType: application/javascript, dataType:
I'm currently making an ajax call to the server to get a list of
I am making ajax call like this $(document).ready(function() { var abc = new Array();
I am making an AJAX call using jQuery to an .ascx control's method in
I'm making an ajax call to a rest API and specified the following header
I am including a jsp fragment by making an ajax call. Now this jsp

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.