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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:21:06+00:00 2026-06-15T17:21:06+00:00

I am working on asynchronous calls with $.getScript which will load the scripts I

  • 0

I am working on asynchronous calls with $.getScript which will load the scripts I need for specific pages. I grab the scripts via an AJAX call to get the scripts I need and then load them in order with the $.when function, I am not sure why the .done() calls immediately, not when the scripts have loaded entirely and placed in the DOM, ready to be used.

For example, the AJAX call returns this:

['js/jquery.cookie.js', 'js/leaflet.js', 'js/index.js']

With this code:

var loadScripts = function(callback)
{
    $.getJSON('url.php', function(response)
    {
        $['when'].call(this, response).done(function()
        {
            callback();
        });
    });
};

Calling it by:

loadScripts(function()
{
    // All scripts are loaded and ready to use
    // but the callback is fired immediately

    // L is undefined
    var map = L.map('map-view').setView([51.505, -0.09], 13);
});

I don’t want to use a library such as Head.js or Require.js, I need a simple script that can load and wait till the loaded functions are in place that can be used. Please note that the scripts list can change and the order as well, so doing $.when($.getScript(), $.getScript()).done() won’t be what I am looking for.

How can I approach this?

  • 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-15T17:21:07+00:00Added an answer on June 15, 2026 at 5:21 pm

    Your ajax call is returning an array of strings, not deferred objects. You need to actually make those strings deferred objects by requesting them with jQuery.getScript and storing the return value.

    var loadScripts = function(callback) {
        $.getJSON('url.php', function(response) {
            var defArr = $.map(response,function(url) {
                return $.getScript(url);
            });
            $.when.apply($, defArr).done(callback);
        });
    };​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Method which does some task asynchronously. Let's call it: AsyncMethod();
I recently refactored some ajax code to make it asynchronous. It was working perfectly
I need i click functions depending on variable unknown length: for(i=0;i<=unknownLength;i++) {$(#group_link_+i).click(function() {//asynchronous call
I' developing a WCF client which makes Asynchronous calls to the WCF server. I'm
I'm working on a C# application in which I set up a few asynchronous
I'm working on asynchronous operation which needs to invoke further asynchronous tasks. I'm trying
I'm developing a Flex application and am having some trouble working with asynchronous calls.
I'm working on an application that makes asynchronous calls to the WebService. I added
I'm working on a project which uses the following technologies: C# (.NET 4.0) WCF
I have been working with synchronous calls in AjaxPro, and I am now looking

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.