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

How can I determine if a jQuery object is deferred?

If I have a function that sometimes returns a deferred object but sometimes a non-deferred object. How can I tell which one it is?
WawaBrother
  • 2,195
  • 3
  • 14
  • 15
47
votes
1 answer

Problems inherent to jQuery $.Deferred (jQuery 1.x/2.x)

@Domenic has a very thorough article on the failings of jQuery deferred objects: You're missing the Point of Promises. In it Domenic highlights a few failings of jQuery promises in comparison to others including Q, when.js, RSVP.js and ES6…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
42
votes
1 answer

Web Workers vs Promises

In order to make a web app responsive you use asynchronous non-blocking requests. I can envision two ways of accomplishing this. One is to use deferreds/promises. The other is Web Workers. With Web Workers we end up introducing another process and…
Mario
  • 6,572
  • 3
  • 42
  • 74
41
votes
5 answers

Retry a jquery ajax request which has callbacks attached to its deferred

I'm trying to implement a system of retrying ajax requests that fail for a temporary reason. In my case, it is about retrying requests that failed with a 401 status code because the session has expired, after calling a refresh webservice that…
cipak
  • 1,414
  • 1
  • 14
  • 20
41
votes
4 answers

Can jQuery deferreds be cancelled?

I have a situation where I want to cancel a deferred. The deferred is associated with an ajax call. Why I am using deferreds I don't use the normal xhr objects returned by $.ajax. I'm using jsonp, which means I can't use HTTP status codes for error…
user879121
38
votes
8 answers

jQuery.when - Callback for when ALL Deferreds are no longer 'unresolved' (either resolved or rejected)?

When multiple Deferred objects are passed to jQuery.when, the method returns the Promise from a new "master" Deferred object that tracks the aggregate state of all the Deferreds it has been passed. The method will either resolve its master…
Alan Spacer
  • 381
  • 1
  • 3
  • 4
37
votes
3 answers

How do I use jQuery promise/deffered in a custom function?

I have a function that gets the location through navigator.geolocation: var getLocation = function( callback ){ navigator.geolocation.getCurrentPosition( callback || function( position ){ // Stuff with geolocation }); }; I would…
hitautodestruct
  • 20,081
  • 13
  • 69
  • 93
35
votes
1 answer

Chain multiple "then" in jQuery.when

I have a function that does something like this: function do_something() { // some code return $.when(foo, bar, baz).then(do_something_else); } function do_something_else(_foo, _bar, _baz) { // do something else return /* the…
Lucas Sampaio
  • 1,568
  • 2
  • 18
  • 36
33
votes
6 answers

How to chain ajax calls using jquery

I need to make a series of N ajax requests without locking the browser, and want to use the jquery deferred object to accomplish this. Here is a simplified example with three requests, but my program may need to queue up over 100 (note that this is…
Graham
  • 7,431
  • 18
  • 59
  • 84
32
votes
4 answers

jQuery .when troubleshooting with variable number of arguments

I'm having an issue with using jQuery.when() to wait for multiple ajax requests to finish before calling another function. Each ajax request will get JSON data, and looks something like this: function loadData(arg){ var ajaxCall =…
Alex
  • 18,332
  • 10
  • 49
  • 53
30
votes
4 answers

jQuery: What is the difference between deferred.always() and deferred.then()?

Seems to me that both does the same thing. Docs: deferred.always() deferred.then()
Niyaz
  • 53,943
  • 55
  • 151
  • 182
30
votes
1 answer

pipe() and then() documentation vs reality in jQuery 1.8

Update: This question is now out of date as the documentation is accurate and up to date. I've been exploring the jQuery Deferred/Promise API for a bit and I'm very confused about the differences between pipe() and then() philosophically and in the…
Adam Terlson
  • 12,610
  • 4
  • 42
  • 63
29
votes
2 answers

How can I tell if an object is a jQuery Promise/Deferred?

I have a function that takes a single argument. I need to be able to tell if this argument is a jQuery Promise or Deferred object. If not, then the value may be of any type and have any properties, so it's not safe to just just for the presence of…
Jeremy
  • 1
  • 85
  • 340
  • 366
29
votes
12 answers

How to make all AJAX calls sequential?

I use jQuery. And I don't want parallel AJAX calls on my application, each call must wait the previous before starting. How to implement it? There is any helper? UPDATE If there is any synchronous version of the XMLHttpRequest or jQuery.post I would…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
25
votes
6 answers

Can I get a jQuery Deferred on document.ready()?

Right after my script is loaded I am making an Ajax request to get some translations. This should always return after the document is ready since I am loading my scripts at the bottom of the page, but I am still curious if it would be possible to…
Daff
  • 43,734
  • 9
  • 106
  • 120
1
2
3
76 77