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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:19:22+00:00 2026-06-13T02:19:22+00:00

I have a function that loads a section. function loadSection(sectionId, onLoaded) { $.when( loadTemplate(sectionId),

  • 0

I have a function that loads a section.

function loadSection(sectionId, onLoaded) {
    $.when(
        loadTemplate(sectionId),
        // etc
    )
    .then(function () {
        // removed for brevity
    }
}

In the loadTemplate function I fade out the current template, and after the fadeout I load the new template.

function loadTemplate(sectionId) {
    // Fade out current template.
    return $content.fadeOut(function () {
        // After fade out, load new template via ajax.
        $.ajax({
            url: settings.apiUrl + 'GetSectionTemplate',
            data: { sectionId: sectionId },
            type: 'post',
            success: function (template) {
                // Add new content and fade in new template.
                $content
                    .html(template)
                    .fadeIn();
            }
        });
    });
}

The problem is that the $.when only waits for the fadeOut function to finish before moving on. I need it to wait for both the fadeOut and the ajax call to finish, but I need the ajax call to execute only after the fadeOut finishes.

  • 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-13T02:19:23+00:00Added an answer on June 13, 2026 at 2:19 am

    Create a deferred object, return it, and then resolve it when the ajax completes:

    function loadTemplate(sectionId) {
        var deferred = $.Deferred();
        $content.fadeOut(function () {
            $.ajax({
                url: settings.apiUrl + 'GetSectionTemplate',
                data: { sectionId: sectionId },
                type: 'post',
                success: function (template) {
                    $content.html(template).fadeIn();
                    deferred.resolve();
                }
            });
        });
        return deferred;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that loads a section of a report. // function to
I have a website that will fade out a section of my website, load
I have a popup function in a program that works well, be re-loads the
On a page I have multiple Jquery UI Sliders that fade out/in the opacity
I have a section of data that loads a main view with a stylesheet
I have a data-upload function that load some data into several tables and processes
I have a large function that I wish to load only when it is
I have a deferred function that binds a mouseenter event: $(window).load(function(e) { var $container
I have a java script function that i have called on body load mousemove()
I have this class that have a function to load other classes and create

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.