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
470
votes
9 answers

Pass in an array of Deferreds to $.when()

Here's an contrived example of what's going on: http://jsfiddle.net/adamjford/YNGcm/20/ HTML: Click me!
JavaScript: function getSomeDeferredStuff() { var deferreds = []; var i = 1; for (i = 1; i <= 10; i++)…
adamjford
  • 7,478
  • 6
  • 29
  • 41
132
votes
4 answers

How do you work with an array of jQuery Deferreds?

I have an application that requires data be loaded in a certain order: the root URL, then the schemas, then finally initialize the application with the schemas and urls for the various data objects. As the user navigates the application, data…
Elf Sternberg
  • 16,129
  • 6
  • 60
  • 68
8
votes
2 answers

jQuery Deferred: $.when() with multiple objects

I need a method to fetch different scripts with a callback. This method works ok: fetchScripts:function() { var _this=this; $.when( $.ajax({ url:_this.url + 'library/script-one.js', type:'get', …
campari
  • 985
  • 2
  • 8
  • 11
7
votes
2 answers

Multiple WHEN condition implementation in Pyspark

I've my T-SQL code below which I've converted in Pyspark but is giving me error CASE WHEN time_on_site.eventaction = 'IN' AND time_on_site.next_action = 'OUT' AND time_on_site.timespent_sec < 72000 THEN 1 -- 20 hours WHEN…
Katelyn Raphael
  • 253
  • 2
  • 4
  • 16
6
votes
3 answers

when multiple ajax calls done

Following is the scenario which doesn't work in the order I want: var masterData = {}; var tableNames = ['table1','table2','table3','table4','table5','table6']; var pullSqlData = function(){ tableNames.forEach(function(value) { …
Nick Germi
  • 403
  • 3
  • 6
  • 15
5
votes
2 answers

Can I pass Promises to jQuery.when(), or only Deferreds?

The documentation for jQuery.when() says that this function takes Deferreds. However, it also says later on that: If a single argument is passed to jQuery.when() and it is not a Deferred or a Promise... which seems to imply that it can take…
Jonathan Aquino
  • 3,780
  • 1
  • 18
  • 19
4
votes
2 answers

await for jQuery.when ajax requests

This code inside async function, does not give the expected result: var result = await $.when( $.get('/api/1'), $.get('/api/2') ); with one request, result will be the output I expect (the response text). However, with these two requests, the…
user3599803
  • 6,435
  • 17
  • 69
  • 130
3
votes
2 answers

Jquery Promise & When without Ajax

I am racking my brain trying to figure out how this is used properly. Most all examples use ajax so maybe this is not even possible. In my example, I create a function, which fades out an element. I realize that .fadeOut can have a callback but I…
VIDesignz
  • 4,703
  • 3
  • 25
  • 37
3
votes
3 answers

Conditionally add to jQuery .when

When my page loads, I make one AJAX call, and then another conditionally upon what is on the page. I want to call a function at the end of both; how do I do it? var dfd = $.when( $.ajax(...) ); if( $("type").val() == "something" ) { dfd.when(…
Sean
  • 14,359
  • 13
  • 74
  • 124
2
votes
1 answer

Attach a callback on click of a button which does an ajax operation

I'm aware that this can be achieved via a Promise but I am struggling to figure out how. jQuery('.parentDiv').on('click', '.link', function(e) { jQuery.when(jQuery('.saveBtn').trigger('click', { 'evtData': 'link' })).then(function { // rest of…
techie_28
  • 2,123
  • 4
  • 41
  • 62
2
votes
1 answer

jquery $.when not working by waiting function in master page

i have some problem when i use jquery.when function in web form using master page This is my code in web form using master page $(document).ready(function(){ $.when(masterPageFunction()).done(function(){ webFormFunction(); }); }) And this…
user3001046
  • 235
  • 1
  • 10
  • 28
2
votes
2 answers

Ansible loop : How can I loop through the array using with_sequence for index

I have multiple arrays with same length. I need to loop through the length and call the elements. I tried the below one and failed. Can you please let me know where I did wrong in this. Or is there any better approach to loop through array…
2
votes
1 answer

What does $.getScript return, and what does it do to scope?

I'm creating a plugin where I want to load a few scripts and for each of them run the function plugin. I created a set of tests/examples (code below). Questions: AJAX passes in the usual data, textStatus, jqxhr set of arguments. But apparently also…
abalter
  • 9,663
  • 17
  • 90
  • 145
2
votes
3 answers

JQuery function returns promise but 'when' still doesn't wait

I've just learned about the $.when().then() functionality. I've been trying to make it work and I've looked at a lot of examples but I'm apparently not understanding fully yet because I can't make it work. I know that whatever function I pass as a…
Dar
  • 383
  • 1
  • 5
  • 16
2
votes
1 answer

AJAX inside $.when giving fist character of the return string

I'm calling an AJAX using a $.when to wait till that ajax completes and return to process the next ajax inside. This is where $.when calling happens: function loadAllData(){ $.when(getCreditorID()).done(function(a1){ console.log("cx id…
1
2 3
11 12