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
2 answers

jQuery .when() .then() promise not adhering inside for loop

I am looping through a basic JSON Object with a for loop. The JSON looks like: { "1": { "project_name": "Example Project Name 1", "client_name": "John Doe" }, "2": { "project_name": "Example Project Name 2", "client_name":…
Zak
  • 6,976
  • 2
  • 26
  • 48
1
vote
1 answer

What attribute should be checked for a registered variable under two Ansible when conditions

How do we check for a registered variable if only one of the two conditions turns out to be true having the same registered variable? Below is my playbook that executes only one of the two shell modules. - name: Check file shell: cat…
Ashar
  • 2,942
  • 10
  • 58
  • 122
1
vote
1 answer

Simultaneous AJAX calls throwing an error

I copied this from a reliable source and altered it for my program var data1 = 'name=Joe'; var data2 = 'name=Jill'; $.when( $.ajax({ url: '/a/sso', …
Dev Studio
  • 13
  • 6
1
vote
1 answer

jquery .when not calling the .done function

I am trying to call a function that presents a modal window to the user. I want to wait for the answer then call another function to perform a save. My initial function is being called, but the function in the done is not. I have attempted to use…
Ken B
  • 101
  • 1
  • 10
1
vote
2 answers

Load scripts asynchronously using getScript

I want use function from path /js/testscript.js, /js/testscript.js is dependent from /script5.js, but testscript.js load after call $(this).testscript(); What am I doing wrong? Scripts are dependent. $.when ( …
1
vote
3 answers

How run function in .scroll() event after ajax call is finish?

I have at ready a function with inside ajax call that extrapolates values from MySql database. Then, in .scroll() event, i have a function that use thise values to animate some divs. The problem is that sometimes .scroll() is run when ajax call is…
Borja
  • 3,359
  • 7
  • 33
  • 66
1
vote
1 answer

Using jquery.when in an object literal

I've got a javascript/jQuery function called addLocation, which is a method of an object literal: addLocation: function(latLng, address=false, elevation=false, pan=false) { $.when(geographic.getAddress(latLng), geographic.getElevation(latLng),…
1
vote
0 answers

When().Then() in AJAX call

I have now tried to read and understand about promises, asynchronous ajax calls and .when and .then. However I am still experiencing some problems with old content being updated and inserted. So please let me know if I am doing something wrong or if…
Kasper Sommer
  • 409
  • 1
  • 6
  • 18
1
vote
2 answers

Applying condition to jQuery.when() deferred functions

I would like to apply a condition to each deferred request within a $.when() function (before the request is made). However placing an if condition inside $.when returns an error. What would be the proper way to do what I essentially describe…
Sebastien
  • 2,607
  • 9
  • 30
  • 40
1
vote
1 answer

jQuery.when: Get the xhr status code

I have two ajax calls that executes some callback after both of them get completed using jQuery.when() $.when(loadDataA(), loadDataB()).done(function(dataA, dataB) { console.log(xhr.status); // How do I get the xhr.status? } I want to know the…
dmferrari
  • 149
  • 12
1
vote
1 answer

Wait for ajax request inside a function : $.Deferred ? $.When ? jQuery

How to wait until the ajax is done inside a deferred function ? Example : function action() { console.log('action is called'); var deferred = $.Deferred(); console.log('do some actions...'); //Wait until the…
Titeufggg
  • 21
  • 3
1
vote
0 answers

Ignore any ajax requests if there is error when getting multiple urls using .when method

var urls = [url_1, url_2, errorUrl, url_4]; $.when.apply($, urls.map(function(url) { return $.ajax({ url :url, success: function( data, status ){ console.log(data) }, error: function(data, status){ …
Danny Kim
  • 809
  • 1
  • 7
  • 15
1
vote
1 answer

How to execute code after multiple $.get() requests using a deferred object?

I'm having difficulties with executing multiple $.get() requests first before executing the total results. I have a request that gets all 50 videos (max), then does a second request (using the same $.get() request with a different pageToken from the…
TheAmazingKnight
  • 2,442
  • 9
  • 49
  • 77
1
vote
1 answer

JQuery ajax stoppen in $.when when server returns 500 error

I make a request to a server with JQuery and the $.when method. $.when(ajaxRequest(param)).done(function(response){ console.log(responseData); }); my ajax function looks like this: function ajaxRequest(param){ var requestedData; return…
rockZ
  • 815
  • 1
  • 12
  • 28
1
vote
2 answers

Why is my `then` event firing before my `when` event is finished?

I have a list of previewed posts on my page. When they're clicked on, they should load the full text of the post, load the comments, and slide down to reveal both. I have one function, partialSlide, that simulates slideDown, but starting at a…
Sinister Beard
  • 3,570
  • 12
  • 59
  • 95
1 2
3
11 12