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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:20:44+00:00 2026-05-21T18:20:44+00:00

I know that ajax calls are asynchronous but there are situations like some synchronous

  • 0

I know that ajax calls are asynchronous but there are situations like some synchronous execution is needed. For Example,

loadMyProfile();
editMyProfile();

These are two javascript functions I want loadMyprofile() should be executed completely and after that it should call editMyProfile(). But that is not happening because its asynchronous.I have heard like callbacks will be the best to handle this situation. So could anyone please explain about callbacks and a sample associated with this example?

Any help will be appreciated!

Thanks,
Karthik

  • 1 1 Answer
  • 4 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-21T18:20:44+00:00Added an answer on May 21, 2026 at 6:20 pm

    I know that javascript is asynchronous

    JavaScript isn’t asynchronous. The language itself defines no asynchronous features at all. The two function calls you’ve shown will be done in order, first loadMyProfile, then editMyProfile. JavaScript does have language features that make asynchronous programming a lot easier, but it doesn’t itself define any asynchronous operations.

    There are two major asynchronous features of the environment in which JavaScript runs in the web browser, though, which (forgive me) I assume is the environment in which you’re trying to use it.

    The first and probably most relevant is that, by default, ajax calls are asynchronous. So for instance, if your loadMyProfile function is making an ajax call, the function will return before that ajax call is completed. This is a feature (and quite a useful one!) of the XMLHttpRequest object.

    The second is the setTimeout and setInterval functions available on the window object in a web browser. setTimeout schedules a function to be called after a timeout (e.g., asynchronously). setInterval schedules a function to be called repeatedly, at an interval.

    A callback is simply a function that gets called when something else happens. The XMLHttpRequest object accepts functions it will call on completion, etc. The functions that you use with setTimeout and setInterval are callbacks. Event handlers are another kind of callback, called when the relevant event occurs in the DOM.

    Looking at your example:

    loadMyProfile();
    editMyProfile();
    

    Let’s assume that loadMyProfile does indeed do an asynchronous ajax call to load the profile information from a server and then display it on the page, e.g.:

    function loadMyProfile() {
        issueAjaxRequest("/some/url", "some data", function() {
            // This function is the completion callback for the ajax call.
            // It gets called *after* `loadMyProfile` has already returned.
            showProfileOnPage();
        });
    }
    

    (That code is syntactically correct, it just uses made-up functions to avoid blinding you with details.)

    Now, if we want to be able to call editMyProfile when the profile has finished loading, we need to make loadMyProfile accept a callback function that it will call when the profile has been loaded:

    function loadMyProfile(callback) {
        issueAjaxRequest("/some/url", "some data", function() {
            // This function is the completion callback for the ajax call.
            // It gets called *after* `loadMyProfile` has already returned.
            showProfileOnPage();
    
            // Call the callback if any
            if (typeof callback === "function") {
                callback();
            }
        });
    }
    

    Then we use it like this:

    loadMyProfile(editMyProfile);
    

    Note there that I don’t have () after editMyProfile. I’m not calling it directly in that statement, I’m passing a reference to it into loadMyProfile, which will call it when the appropriate time comes.

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

Sidebar

Related Questions

I'm new to AJAX and PHP but I know that PHP is a server-side
I understand that Javascript doesn't have multiple threads, but I'd like to know if
I'm getting some strange results sending multiple asynchronous AJAX calls to the same java
I know that the huge advantage of doing AJAX calls is that the rest
Is it possible to know that a HTTP request is from Ajax?If yes, how?
I know that it's a subject that can raise a lot of debate, but
I know that I should put all the html elements in body tag, but
I know that it's possible to implicitly provide asynchronous interaction using: Asynchronous Delegates Asynchronous
I know that this has already been asked here but the answer (using a
I would like to have filtering page that performs ajax requests to asynchronously update

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.