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

how do I defer javascript execution until an asynchronous method completes execution

I have been looking into Jquery's when then and deferred keywords & functions but I couldn't get how do I apply them for a simple 3rd party asynchronous callback method in the ready() function of one of my views. What actually happening is that my…
user2918640
  • 473
  • 1
  • 7
  • 25
0
votes
1 answer

unable to make jquery when & then complete before function return

I want the sequence of execution to be as follows. 1. unattach(x) 2. updateLists(y) 3. console.log("completed execution of function update") Only after both the functions (unattach & updateLists) have completed execution then the update function…
Priyanka A
  • 63
  • 1
  • 1
  • 6
0
votes
1 answer

Jquery .when() not waiting

Im trying to validate a phone number against a country code in Backbone.js. I need to wait until after the the ajax callback is executed before returning the result of the validation. I'm using Jquerys when method. The model's validate function is: …
user1716672
  • 1,073
  • 2
  • 20
  • 44
0
votes
1 answer

Detecting when variable equals another variable with jQuery ($.when()?)

Currently trying to detect when a YouTube video in a playlist ends so I can play the next one ( Adding event handler to loop through dynamically created playlist (YouTube API) ). I'm now trying to figure out when one variable is equal to another, so…
Amir
  • 281
  • 5
  • 15
0
votes
1 answer

A redirection method does not wait for a posting method to be finished even using $.when (AJAX)

Goal: I want to use a 'post' method to send a http request to another website (ignore data), and then redirect to another page. Like this, $.when($.post("https://www.example.com/result") ) .then( $(location).href('page2.html')); It seems…
0
votes
1 answer

$.when not waiting for Ajax request to finish

I want to first render a view with Backbone.js that displays an Article pulled from the server. I then want to mark this as "seen" and return the count of unseen messages to the router as it needs to be made available to other views. So in my…
user1716672
  • 1,073
  • 2
  • 20
  • 44
0
votes
1 answer

How to have first function "foo1()" finished processing before running $.when() afterward??

I'm using JQuery v2.0.0 How do I make these functions run in top to bottom order instead of an asynchrous-like effect or order, meaning don't let the function "foo2()" run before the function "foo1()" is done first. foo1(); $.when( foo2() ) …
fletchsod
  • 3,560
  • 7
  • 39
  • 65
0
votes
2 answers

jQuery using .when and pushing an array

Have been looking into getting callbacks for ajax() responses using $.when I'm still unsure how this works fully but this is what I would like the below to do. When a user adds a town and country per line, it goes to the url in the .ajax() I get a…
ngplayground
  • 20,365
  • 36
  • 94
  • 173
0
votes
2 answers

Wait until all jquery ajax request are done? (part 2)

I checked this post and the answer is really good: Wait until all jQuery Ajax requests are done? But I just want to be more generic: I wonder how we can use this logic for a List of services (ajaxservices) and list of callbacks e.g. ajaxservices =…
Jaider
  • 14,268
  • 5
  • 75
  • 82
0
votes
1 answer

Jquery when ; value not set

I need to repalce the href of a 'title' class elements in the page on the basis of the 0 or x value returned from http://kasaragodyellowpages.com/pagedata.php?id=x. this url is set to 1 for testing. work currectly to ajax requests. problem is late…
Abel Jojo
  • 758
  • 3
  • 14
  • 30
0
votes
1 answer

Cant get then to trigger after when

The following code should be straightforward //Generic success routine, let the developer know, store the results function genericSuccess( _data , textStatus , jqXHR ) { data[this.url] = _data; } jQuery.when( $.ajax({ url: metaKey, success:…
tomdemuyt
  • 4,572
  • 2
  • 31
  • 60
0
votes
2 answers

Using $.when to wait for ajax to complete

I need to wait for a certain ajax request to complete before going on. Since this request is triggered from different anchors, I wrapped it in a function. What happens after the function with the first ajax has finished, is a second ajax request. At…
Explicat
  • 1,075
  • 5
  • 16
  • 40
0
votes
2 answers

Executing one function after another

All of these functions are in the main function which is called after jQuery async AJAX success event and it runs every second. Each of the three functions call specific functions within them as well. This is the basic javascript code I…
zen
  • 1,115
  • 3
  • 28
  • 54
0
votes
2 answers

Chaining an indeterminate number of Ajax request

I need to chain an unknown (but definitely finite) number of ajax requests. I wanted to create a goAjax() function and watch it with $.when and in my .then() block determine whether or not to call goAjax() again... here is my problem, $.when() only…
Jeremythuff
  • 1,518
  • 2
  • 13
  • 35
0
votes
2 answers

$.done() code gets executed before $.when()

In my project I m using 2 versions of JQuery.js, so I resolved the conflict using $.noConflict() for my latest version of JQuery to variable named jq172. Now I have used jq172.when().done()construct to show loading status image until all ajax…
Shaggy
  • 315
  • 2
  • 9
  • 23
1 2 3
11
12