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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:45:16+00:00 2026-05-24T04:45:16+00:00

The jQuery docs strongly urge you not to set async to false when performing

  • 0

The jQuery docs strongly urge you not to set async to false when performing an $.ajax request.

However, I’m seeing common solutions to synchronicity problems involve doing just this. And then I’ve seen people been chastised for going against the docs’ recommendation.

With that said, I have attempted to use a promise to avoid using async:false with no luck.

Here is the code I’m using. I have an onclick event that calls addToOrder:

function saveTemplate() {
    var formData = getFormData();
    return $.ajax({
        type: "POST",
        url: "/p/session/save/" + sessionid + "/template/<?php echo $templateID ?>/",
        data: formData,
        async: true,
        success: function(msg){
            var rsp = $.parseJSON(msg);
            if (rsp.response === 'Saved') {
                sessionid = rsp.sessionid;
                $("#save-preview-data-response").html("&nbsp;&nbsp;&nbsp;" + rsp.response).fadeIn(100).delay(1000).fadeOut(1000);
            } else {
                $("#save-preview-data-response").css('color','#ff0000').html("&nbsp;&nbsp;&nbsp;" + rsp.response).fadeIn(100).delay(1000).fadeOut(1000);
            }
        }
    });
}

function addToOrder() {
    var saved = saveTemplate();
    var issaved;
    saved.success(function(e) {
        var rsp = $.parseJSON(e);
        issaved = (rsp.response == 'Saved') ? true : false;
    });
    if(issaved) {
        $.ajax({
            type: "POST",
            url: "<?php echo $baseURL; ?>addToOrder/respond/json",
            data: "sid=" + sessionid,
            async: true,
            success: function(msg){
                var rsp = $.parseJSON(msg);
                if (rsp.response === 'Saved') {
                    alert(msg);
                }
            }
        });
    }
}

issaved will always evaluate to false, as it is being evaluated before saveTemplate has had time to run. The only solution I have found is to set async:false but I am taking the warnings I’ve seen serious and would rather not. What other solutions are there?

  • 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-24T04:45:17+00:00Added an answer on May 24, 2026 at 4:45 am

    Tactics to avoid using async:false with jQuery?

    Learn to love callbacks. 🙂 When people do this:

    // The synchronous way
    function doSomething() {
        var foo;
        $.ajax({
            url: "/the/url",
            async: false,
            success: function(response) {
                foo = response.foo;
            }
        });
        return foo;
    }
    
    // ...somewhere else, we use it
    function flurgle() {
        var bar = /* go get `bar` from somewhere */;
        var x = 52;
    
        if (doSomething() === bar) {
            x -= 10;
        }
        niftyFunctionUsing(x);
    }
    

    …the event-driven, asynchronous way really isn’t that much different:

    // The asynchronous way
    function doSomething(callback) {
        $.ajax({
            url: "/the/url",
            success: function(response) {
                callback(response.foo);
            }
        });
    }
    
    // ...somewhere else, we use it
    function flurgle() {
        var bar = /* go get `bar` from somewhere */;
        var x = 52;
    
        doSomething(function(foo) {
            if (foo === bar) {
                x -= 10;
            }
            niftyFunctionUsing(x);
        });
    }
    

    Since callbacks frequently involve closures (the above ones do, that’s how we’re accessing x and bar), this article from my blog may be helpful: Closures are not complicated

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

Sidebar

Related Questions

I'm doing an ajax lookup using jQuery, which is all going swimmingly. However I
I am using jquery form validation plugin http://docs.jquery.com/Plugins/Validation/validate How can I set a callback
At http://docs.jquery.com/UI/Tabs#Example there is a short HTML example of how to use JQuery UI
I'm using the JQuery tooltip plugin - http://docs.jquery.com/Plugins/Tooltip With the basic implementation: $(.tooltip).tooltip(); Instead
I'm trying to use the autocomplete plugin for jQuery (this one http://docs.jquery.com/Plugins/Autocomplete ). My
All, I am trying to use JQuery's URL Validator plugin. http://docs.jquery.com/Plugins/Validation/Methods/url I have a
According to the jQuery docs, I need to escape metacharacters that occur in my
After studying the docs for a while, I came up with my first jQuery
I'm confused about scrollTop() . jQuery docs say it should be displaying a number
How would I slideDown a div and animate the width together. The jquery docs

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.