Home > General > $.When.apply($

$.When.apply($

Sign in to comment Contact GitHub API Training Shop Blog About © 2017 GitHub, Inc. function AccountData(txtseq) { var acc; var accountno = ""; var textbox = ""; if (txtseq var promise = processItem(data[0]); for(var i = 1; i < data.length; i++){ promise = $.when(promise, processItem(data[i])); } –MPavlak Apr 27 '16 at 17:27 add a comment| Your Answer draft saved After some timeout, resolve the current Deferred //in the real world, this would probably make an AJAX call.

Do hotels in Europe permit two adults and two kids to all stay in just one room? Is it safe to buy a router if its serial number and other details are exposed on the web? I'm using JQuery 2.1.0 in this example. Normally, $.when takes a variable number of arguments, using .apply makes it possible to pass it an array of arguments, it's very powerful. http://stackoverflow.com/questions/14777031/what-does-when-apply-somearray-do

In it, you'll get: The week's top questions and answers Important community announcements Questions that need answers see an example newsletter By subscribing, you agree to the privacy policy and terms A derogatory term for a book or other printed material My DM insists on rolling a single save for groups affected by AoE save spells. Who are the oldest characters in A Song of Ice and Fire? Is 💩 (Unicode 'pile of poo') considered NSFW?

setTimeout(function() { dfd.resolve(); }, 2000); return dfd.promise(); } function everythingDone(){ alert('processed all items'); } It this a bug? Convert arg to uppercase to pass as variable Is there a word for the opening of a song? arrJqx.push($.ajax ({ url: "/echo/json/", dataType: "json", data: {json: "{\"text\": \"foo\"}"}, type: "POST" })); // This call has a five second delay before the response And $.when() function will ensure that we wait for all the pagers ring before we eat together.However, there is a little problem. $.when() function accept lists of arguments, so we have

one after the other or in parallel ? –Darshan Nov 25 '13 at 17:23 17 @Darshan: You don't "run" promises. Join them; it only takes a minute: Sign up How to get responses from $.when.apply($, deferreds) Ask Question up vote 0 down vote favorite How do I access the unknown number It simply put that request on a queue somewhere behind curtain and do it whenever it has time to do so. http://stackoverflow.com/questions/33173249/returned-value-for-when-apply-maparray-somefunctionx You signed in with another tab or window.

About 45914 results .apply is used to call a function with an array of arguments. It's used to say "when all these promises are resolved... You hold on to the pager and you can go to the next shop and take care of other errant until the page rings. The behaviour of floating point division by zero Why do my users 're'select the amount in the cart?

See my jsfiddle.net/logankd/s5dacgb3 that I made from your example. http://jsfiddle.net/abenrob/mQ3hY/ click on a console message to navigate to the supporting MSDN documentation. Normally, $.when takes a variable number of arguments, using .apply makes it possible to pass it an array of arguments, it's very powerful. Do some debug trace $('body').append('processed all items'); } JavaScript CSS Language HTML Doctype XHTML 1.0 Strict XHTML 1.0 Transitional HTML 5 HTML 4.01 Strict HTML 4.01 Transitional HTML 4.01 Frameset Body

The OP asked for what the apply() does and you suggested a terrible alternative that should never be used :) that IS what the down vote button is for. setTimeout(function() { dfd.resolve() }, 2000); // 3.1.3. You need to iterate the arguments where each argument is an array of [responseData, statusText, xhrObj] var deferreds =[]; for (var i=0; i<6; i++){ deferreds.push($.get('data.json')) } $.when.apply(null, deferreds ).done(function(){ console.log(arguments) for( For very high-net worth individuals, does it make sense to not have insurance?

In it, you'll get: The week's top questions and answers Important community announcements Questions that need answers see an example newsletter By subscribing, you agree to the privacy policy and terms more stack exchange communities company blog Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and Is this "fall of industrial production" graph accurate? Connect to Services Connect to personal services for more relevant search results across services.

Importance of using all fingers while playing guitar Is there a word for the opening of a song? Embed Embed this gist in your website. I would like to use this like the gentleman above described it.

Related 2243event.preventDefault() vs.

more stack exchange communities company blog Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and arrJqx.push($.ajax ({ url: "/echo/json/", dataType: "json", data: {json: "{\"text\": \"bar\"}", delay: 5}, type: "POST" })); // The server response is not displayed in an There are a ton of cases where you'd want to know as soon as something fails, not wait for everything to complete and check if there were failures. Passing the array itself to $.when wouldn't work, because it expects its parameters to be promises, not an array.

For example: $.when.apply($, [def1, def2]) Is the same as: $.when(def1, def2) But the apply way of calling allows you to pass an array of unknown number of parameters. (In your code, Create DOMs and attach them to HTML page. when a order is ready, place the food on the tray foodTray.push(food); }); // 2. Sign in to comment Contact GitHub API Training Shop Blog About © 2017 GitHub, Inc.

The first reject will fire the always, but not the .then. What is the reason to use the Heal skill assuming that other means of healing are not prohibited? do something". anyFunction.apply(thisValue, arrayParameters) calls the function anyFunction setting its context (thisValue will be this) and all the parameters in arrayParameters.

Links About JSFiddle Status page by updown.io JSFiddle Roadmap suggest and vote for features Like JSFiddle? Declare an array of Deferred objects var processItemsDeferred = []; // 3. Embed Share Copy sharable URL for this gist. Hot Network Questions Who are the oldest characters in A Song of Ice and Fire?

Function called when all deferred are resolved function everythingDone(){ // 4.1.1. Return that Deferred (to be inserted into the array) return dfd.promise(); } // 4.1. Automatically draw hidden portions of paths with dashed lines How do I get through the Lost Woods?