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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:29:57+00:00 2026-06-13T01:29:57+00:00

I have a function that loads a section of a report. // function to

  • 0

I have a function that loads a section of a report.

// function to load section 
function loadSection(sectionId) {

    $.when(

        // Now load the specified template into the $overlay.
        loadTemplate(sectionId),

        // After the template is in place we need to identify all
        // the editable areas and load their content.
        loadEditables(sectionId)

    )
    .then(function () {

        // Now find all section link elements and wire them up.
        buildSectionLinks(),

        // Find all hover elements and attach the hover handlers.
        loadHovers()

    });

}

The idea is that we will load a template, then iterate over the template to find all of the “editables”, which are just user-provided content areas within a template. Once the template and all editables have been loaded we then do some processing over the markup to do things like tie click events to certain elements. All template and editable ajax calls need to be finished before the processing happens.

The call to loadTemplate(sectionId) works just fine with jQuery.when because I’m only doing one ajax call.

// This function goes out to an AJAX endpoint and gets the specified
// report template and appends it to the overlay DIV.
function loadTemplate(sectionId) {
    return $.ajax({
        url: settings.templateUrl,
        data: { sectionId: sectionId },
        type: 'post',
        success: function (template) {
            $overlay.append(template);
        }
    });
}

The loadEditables(sectionId) function is not as simple to implement because I have to loop through all the editables and do an ajax call for each one.

// This function loads content for all editables defined in the template.
function loadEditables(sectionId) {
    // Grab all editables into a jQuery wrapped set.
    var $editables = $('#template .editable');

    // Loop through each editable and make an AJAX call to load its content.
    $editables.each(function () {
        var $editable = $(this);

        $.ajax({
            type: 'post',
            url: settings.editableUrl,
            data: {
                sectionId: sectionId,
                editableIndex: $editable.data('editableindex')
            },
            success: function (editable) {
                if (editable.hasData)
                    $editable.html(editable.content);
            }
        });
    });
}

In loadTemplate I was able to simply return $.ajax(...) in the function to satisfy the $.when(...). In here I’m looping through the wrapped set and doing a new ajax call for each element in the set. How can I make sure all these calls are done before firing the processing functions (buildSectionLinks() and loadHovers())?

  • 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-13T01:29:58+00:00Added an answer on June 13, 2026 at 1:29 am

    Store the promise objects in an array then pass that array to $.when using .apply

    function loadEditables(sectionId) {
        // Grab all editables into a jQuery wrapped set.
        var $editables = $('#template .editable'),
            defArr = [];
    
        // Loop through each editable and make an AJAX call to load its content.
        $editables.each(function () {
            var $editable = $(this);
    
            defArr.push($.ajax({
                type: 'post',
                url: settings.editableUrl,
                data: {
                    sectionId: sectionId,
                    editableIndex: $editable.data('editableindex')
                },
                success: function (editable) {
                    if (editable.hasData)
                        $editable.html(editable.content);
                }
            }));
        });
        return $.when.apply($,defArr);
    }
    
    • 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. function loadSection(sectionId, onLoaded) { $.when( loadTemplate(sectionId),
I have a data-upload function that load some data into several tables and processes
I have a popup function in a program that works well, be re-loads the
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
I have a report that needs to show multiple pictures. In the detail section
I have a section of data that loads a main view with a stylesheet
I have a website that will fade out a section of my website, load

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.