Questions tagged [.when]

.when is a jQuery function for executing a function when the included AJAX request(s) have been completed. It usually precedes .then.

.when is a jQuery function for executing a function when the included AJAX request(s) have been completed. It usually precedes .then. An example of a usage would be:

$.when($.post(foo1), $.post(foo2)).then(function (a, b) {
  /*
    execute this when requests to foo1 and foo2 have been made. a[0] and b[0] contain
    the results returned by the two pages foo1 and foo2.
  */
});

Documentation

174 questions
1
vote
1 answer

jQuery Deferred not working

I'm trying to use jQuery Deferred objects to push left a div #image_viewer only after all the images have been prepend-ed into it through an Ajax call. function myFunc() { return $.Deferred(function(apples) { for ( j=0; j<…
blurgoon
  • 335
  • 3
  • 13
1
vote
0 answers

Jquery ajax call in a loop, wait for every call to be completed

I have this ajax function, that returns an array of prices: function get_date_price(checkdate, type_r) { return $.ajax({ type: "POST", url: "hotels/get_check_date_price", data: {id: $("#hotel_id").val(),…
Aminesrine
  • 2,082
  • 6
  • 35
  • 64
1
vote
3 answers

How to chain jquery $.when

I'm using $.when.apply($, arrayOfDeferreds).then(function() { var args = Array.prototype.slice.call(arguments); var anotherArrayOfDeferreds = []; args.map(function(item){ anotherArrayOfDeferreds.push(item.getSomething()); //…
Yu Wu
  • 11
  • 2
1
vote
1 answer

Can I nest whens?

Working in SharePoint, trying to retrieve and process data from multiple lists. The return from the second list is getting paged, which breaks the ordering (as far as I can tell). So, my thought was to LITERALLY nest a new 'when' for this second…
mired
  • 51
  • 1
  • 1
  • 4
1
vote
2 answers

group_concat in mysql with "case when " conditions

I wrote sql code in mysql environment to concat the data . But, I couldn't get the correct result , and I am confusing about what is wrong with my sql code. my sql code is as follows: SELECT case when cc.complex_check_id = cmt.comp_o_id then…
Anwar Ahmat
  • 219
  • 5
  • 14
1
vote
1 answer

How to use jQuery.when() with an array of URLs?

How would i have to change this example $.when( $.getScript( "/mypath/myscript1.js" ), $.getScript( "/mypath/myscript2.js" ), $.getScript( "/mypath/myscript3.js" ), $.Deferred(function( deferred ){ $( deferred.resolve ); …
user1014412
  • 359
  • 1
  • 2
  • 15
1
vote
1 answer

Change the in array functions context and pass the array to $.when

Hi all I have this working method to call an array of functions at recurring intervals. Here you can see the object with the methods to add/remove functions in the array and the functions to start/stop the calling interval. (You have to focus only…
Mat
  • 11
  • 3
1
vote
1 answer

Javascript: Is there a way to specify infinite input parameters for Parse.Promise.when?

Looking at the documentation for Parse.Promise.when (https://www.parse.com/docs/js/symbols/Parse.Promise.html#.when), currently, there are two ways of specifying it. The first is with comma separated input parameters for "when" and followed by comma…
user3145336
  • 311
  • 5
  • 15
1
vote
2 answers

How to tell when multiple functions have completed with jQuery deferred

I have 3 functions which handle data pulled in from AJAX, they update the page after the ajax function is called. When the AJAX function is called I show a loader, I want to hide the loader after the AJAX has completed and the functions have…
zizther
  • 814
  • 1
  • 10
  • 26
1
vote
2 answers

JQuery deferred.done executes predefined function instantly, but not function declared inside

My problem is a weird one, as described in the title. Here's the code: Case 1: var first = $.ajax({ // about 500ms request url: myUrl success: function() { console.log(1); } }); var second = $.ajax({ // about 200 ms…
mathaway__
  • 23
  • 3
1
vote
1 answer

Can I rely on the order of responses from jQuery.when on multiple Ajax requests

Per this post: https://stackoverflow.com/a/17548609/985704 Using jQuery.when to perform multiple simultaneous ajax requests. var requests =…
egret
  • 179
  • 2
  • 8
1
vote
1 answer

jquery '$.when': how to trigger 'done' callback even in case of error

Jquery's $.when function executes the 'done' callback when all promises are resolved, but not if any of them result in errors. How do I execute the 'done' callback once all the promises have had a result, either success or error?
tldr
  • 11,924
  • 15
  • 75
  • 120
1
vote
1 answer

javascript when function and arbitrary number of requests

I been reading a little about the jquery when and done functionality, but what is the best way to handle an arbitrary number of requests: var t = []; _.each(searchData.get("products"), function(productId, index){ fetchingProduct =…
1
vote
1 answer

How to make use $.when.apply with Backbone.Collection or Models

The code below is small function to guaranteed all Backbone.collection / model fetch operation. The only problem that I'm facing right now is deferred.resolve where you can see the Models is actually an array. fetchData: function(Models) { var…
Muhaimin
  • 1,643
  • 2
  • 24
  • 48
1
vote
1 answer

jquery window animate after masonry

i am trying to get a window animate fired after a $container.masonry() is fully executed. basically i resize images in a masonry container on click, and want to scroll to the top of that resized image afterwards. here is a…