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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:57:34+00:00 2026-06-02T21:57:34+00:00

I have the following parameters: a = [{param:’a’}, {param:’b’}, {param:’c’}] I’d like to make

  • 0

I have the following parameters:

a = [{param:'a'}, {param:'b'}, {param:'c'}]

I’d like to make a get request for each parameter, like this:

a.map(function(ai){return $.get('myapi/get?ai='+ai.param)})

How do I do something once all the get requests have finished?

I have tried using $.when, like this:

$.when(
    a.map(function(ai){return $.get('myapi/get?ai='+ai)})
)
.done(function(results){
    results.forEach(function(ri, i){
        ri.success(function(result){
            a[i].result = result
        }
    }
    do_something_with(a)
}

unfortunately I am clearly misunderstanding this $.when().done() idiom as when I call do_something_with(a) I don’t have the new .result attribute. I’m guessing it’s because when is seeing a single array and so just passes straight into the .done(), as opposed to waiting for each component get to finish.

Any help would be appreciated!

  • 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-02T21:57:36+00:00Added an answer on June 2, 2026 at 9:57 pm

    You need:

    $.when.apply($, myArray);
    

    i.e. using Function.apply to call $.when() with this === $ and the rest of the arguments being the contents of the array myArray, where that array contains the deferred objects returned by each call to $.get.


    To answer the second question from your comments, you could pass your array of deferred objects through this map function, which returns a new array of deferred objects which will be resolved at completion of each AJAX call, regardless of whether it succeeded or not.

    var alwaysDef = def.map(function(old) {
        var def = $.Deferred();
        old.always(def.resolve);
        return def;
    });
    

    Note that I’m not sure what parameters (if any) will end up being passed to the final .done function in this instance.

    If that matters, the deferred objects are always called in order, so you can register a .done handler for each of the original promises that stores the AJAX results in an array for later use, and a .fail handler that stores a null value instead.

    That will ensure that your final .when handler isn’t invoked until after each of the individual results are available to you.

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

Sidebar

Related Questions

In python I have the following function: def is_a_nice_element(element, parameter): #do something return True
I have the following xml: <parameters> <parameter >value1</param> <parameter >value2</param> </parameters> with the following
I have the following PS script: function Install-BizTalkApplication { param( [Parameter(Position=0,Mandatory=$true,HelpMessage=Msi file should be
I have the following function //simple function with parameters and variable function thirdfunction(a,b,c,d){ console.log(the
Say I have the following: [Test] // would like to parameterize the parameters in
I have a unmanaged C++ function with the following signature: int function(char* param, int
In PowerShell I have this function: function RunSQLServerQuery { param ( [string]$server = .,
I have the following function: public DataTable GetRecordSet(String query, string[] parameters) It is typically
I have the following ExtJS controller code: init: function() { this.control({ '#menuitem-A': { click:
Say I have a model called User that has the following parameters: favorite_color, favorite_animal,

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.