Questions tagged [jquery-deferred]

jQuery's deferred (also known as promises and futures) can be used to manage callback queues

jQuery.Deferred(), introduced in version 1.5, is a chainable utility object that can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.

1147 questions
519
votes
12 answers

jQuery deferreds and promises - .then() vs .done()

I've been reading about jQuery deferreds and promises and I can't see the difference between using .then() & .done() for successful callbacks. I know Eric Hynds mentions that .done() and .success() map to the same functionality but I'm guessing so…
screenm0nkey
  • 18,405
  • 17
  • 57
  • 75
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
284
votes
11 answers

How can jQuery deferred be used?

jQuery 1.5 brings the new Deferred object and the attached methods .when, .Deferred and ._Deferred. For those who haven't used .Deferred before, I've annotated the source for it. What are the possible usages of these new methods, how do we go about…
Raynos
  • 166,823
  • 56
  • 351
  • 396
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
121
votes
4 answers

What are deferred objects?

jQuery 1.5 adds "Deferred Objects". What are they, and what exactly do they do?
Mohammad Ali Akbari
  • 10,345
  • 11
  • 44
  • 62
108
votes
4 answers

what is difference between success and .done() method of $.ajax

Can anyone help me? I am not able to understand the difference between success and .done() of $.ajax. If possible please give examples.
Poonam Bhatt
  • 10,154
  • 16
  • 53
  • 72
98
votes
3 answers

When should I use jQuery deferred's "then" method and when should I use the "pipe" method?

jQuery's Deferred has two functions which can be used to implement asynchronous chaining of functions: then() deferred.then( doneCallbacks, failCallbacks ) Returns: Deferred doneCallbacks A function, or array of functions, called when the Deferred…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
90
votes
3 answers

Reactjs async rendering of components

I want to render my component after my ajax request is done. Below you can see my code var CategoriesSetup = React.createClass({ render: function(){ var rows = []; …
tuna
  • 6,211
  • 11
  • 43
  • 63
86
votes
2 answers

Deferred versus promise

What is the difference between Deferred and Promise other than the jQuery versions? What should I use for my need? I only want to call the fooExecute(). I only need the fooStart() and fooEnd() to toggle the html div status for example. //I'm using…
fletchsod
  • 3,560
  • 7
  • 39
  • 65
70
votes
3 answers

jQuery.when understanding

I am trying to use the jQuery.when to fire two ajax requests and then call some function after the two requests have completed. Here's my code: var count = 0; var dfr; var showData = function(data) { dfr.resolve(); alert(count); // Do…
Ashish
  • 2,544
  • 6
  • 37
  • 53
63
votes
1 answer

how does jquery's promise method really work?

I don't really understand what delegate and promise are. According to the docs - delegate would bind a selector and event to some sort of wrapping container that can be used again at a later time for current and future items. promise() would…
robx
  • 3,093
  • 2
  • 26
  • 29
62
votes
3 answers

jQuery Deferred - waiting for multiple AJAX requests to finish

I have a three layer deep chain of deferred ajax calls, and ideally they are going to kick the promise all the way up when the deepest layer finishes (makes me thing of Inception... "we need to go deeper!"). The problem is that I'm sending off many…
brittohalloran
  • 3,534
  • 4
  • 28
  • 27
51
votes
2 answers

Asynchronous JavaScript - Callbacks vs Deferred/Promise

Possible Duplicate: What are the differences between Deferred, Promise and Future in Javascript? Lately I've been making an effort to improve the quality of my JavaScript applications. One pattern I've adopted is to use a separate "data context"…
Ben Foster
  • 34,340
  • 40
  • 176
  • 285
49
votes
7 answers

How to prevent the white 'flash' on page load created by background image loading delay?

The problem is, on most sites on the web, there are background images. They take time to load. Ordinarily, it wouldn't be a problem if the images were optimized, and small enough. However, on some of my sites, the javascript files find their way to…
alt
  • 13,357
  • 19
  • 80
  • 120
49
votes
2 answers

Return already resolved promise

I have an existing project that has a lot of asynchronous functions that return promises. I'm adding some caching so that in some cases the asynchronous functions will complete synchronously and would like to make this code shorter/better if…
eselk
  • 6,764
  • 7
  • 60
  • 93
1
2 3
76 77