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
0
votes
4 answers

How to make an array of Deferred objects

Am new to Deferreds and Promises. Here is my [simplified] code, which is defined within a JavaScript object: myFunction: function(d, cb) { return $.ajax('/myURL', { contentType: 'application/json', data: d, …
QYH
  • 46
  • 3
0
votes
2 answers

Why $.when() not wait when the function is completed?

I want to update the page only when the function "removeDocx" be executed. But in my case, timeout of the timer is perceived as the completion of "wait" function. Where is the problem, and how can I solve it? There is an example of code: $(function…
Kseniya Yudina
  • 137
  • 1
  • 11
0
votes
1 answer

Getting an array of responses in then using $.when.apply

I have the following code: var requests = []; var files = ['one.html', 'two.html', 'three.html']; for(var i = 0; i
jacobdo
  • 1,605
  • 3
  • 15
  • 34
0
votes
1 answer

Promise resolve misses one value for asynchronous request loop

Thanks to the help from here I could build a loop for posts and resolve the promises in order to handle asynchronous requests. But for some reason the loop to get the resolved promises and according values always misses one step. I tried to apply…
Blind Seer
  • 492
  • 1
  • 5
  • 17
0
votes
2 answers

passing data from .when to .then in jQuery

I'm trying to use a .when with an .each to loop through some elements and .then do something with the results. But I'm not sure how to store the results from the .when to use in the .then. for example var widget_data = []; $.when( …
waspinator
  • 6,464
  • 11
  • 52
  • 78
0
votes
2 answers

$.when().done() Jquery functions execution flow not working

I am calling two functions in $.when(f1,f2) but done() is called before f2 is resolved. But if I put alert() statement in done It is working fine. function f1(){ var d= new $.Deferred(); .......code...... d.resolve(); return…
N.Moudgil
  • 709
  • 5
  • 11
0
votes
1 answer

jquery correct syncronous ajax call

i need to call a jquery ajax funtion inside a function and check response data function checkInput(){ var success; $.ajax({...}).then(function (data) { success = data.response console.log(success); // true/false correct! …
AldoZumaran
  • 547
  • 5
  • 23
0
votes
1 answer

Running multiple deferred groups sequentially

So I have been messing around with $.Deferred() and can't quite get it to work the way I want. The idea is to run a group of 10 items, wait for it to finish, run the next group, wait for it to finish, etc. The code below produces this output (3)Item…
MTNewton
  • 13
  • 3
0
votes
1 answer

Why does my jQuery .done function not fire after .when code?

I tried to load some scripts with jQuery, and after the download is finished I want to execute some code. I expected to get alert(1) called but nothing happens. The scripts are correctly downloaded (checked in console). $.when( $.getScript…
sascha2014
  • 103
  • 1
  • 12
0
votes
2 answers

jQuery $.when in a loop, dosen't wait for each call to be completed before continuing the loop

I use $.when to call an ajax function in a loop: for ( var i = 0; i < 4; i++ ){ $.when(get_total_price("var1","var2")).then(function (v) { console.log("i= "+i); }); } I expect that in every iteration, it waits for the ajax call to…
Aminesrine
  • 2,082
  • 6
  • 35
  • 64
0
votes
1 answer

Dynamically adding sequential actions using deferreds

Here is my current code: https://gist.github.com/benjamw/f6d5d682caddd4c1e506 What I'm trying to do is: based on what the URL is when the user hits the page, pull down different data from the server, and when that's all done, render the page with…
Benjam
  • 5,285
  • 3
  • 26
  • 36
0
votes
1 answer

how to pass the result of a backbone function into jQuery $.when().then()?

NOTE: I am using jQuery version 1.7.2. I'm trying to understand jQuery promises and deferred objects. I have the following code: var that = this; var dataRetrieved = that.retrieveData(); $.when(dataRetrieved).then(function(data) { …
tdc
  • 5,174
  • 12
  • 53
  • 102
0
votes
1 answer

SELECT the newest record in Oracle based on date, activity in the list of records

I have following data in one of the table I would like to distinguished them based on the highlighted record, for example: when I select record based on Foreign_key column and the second record is "Content = Response OR Process_id = 11" then I…
Adds
  • 191
  • 3
  • 13
0
votes
0 answers

JQuery script to wait until Google Maps API finish the request

I am building a script which will get users locations using the Google Maps API. Once the data is retrieved I want to send them via a form in order to pass them to PHP. I read a little about it and found a jquery function that waits until the…
user1857756
  • 385
  • 3
  • 4
  • 14
0
votes
3 answers

Transforming Sync functions to Async

I am trying to make a series of synchronous calls into asynchronous, and I'm using when...done... I'm new at this stuff, but from all the reading I've been doing on this subject the last two days, my code below should work. Well, it does work, but…
tagale
  • 1