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

jquery defer and promises with getScript

I've been investigating the new(ish) deferred object in jQuery and I stumbled across this website article here . In the article is some code designed to cache scripts so they don't get requested more than once. var cachedScriptPromises = {}; …
James South
  • 10,147
  • 4
  • 59
  • 115
8
votes
2 answers

jQuery Deferred not calling the resolve/done callbacks in order

Code example: http://jsfiddle.net/MhEPw/1/ I have two jQuery Deferred objects. I want to have more than one 'async' request happening - and after they all run I want the callbacks (the .done functions) to be run in order they were specified in.…
Adam Silver
  • 250
  • 2
  • 6
8
votes
2 answers

Deferred and Ajax

Reading a JSON-Service like this: $.ajax({ url:'activeIDs', success : function(data){ // data = [14,15] var tableRows = []; for (var dataIndex=0; dataIndex < data.length; dataIndex++) { var isLast = dataIndex == (data.length - 1); …
Grim
  • 1,938
  • 10
  • 56
  • 123
8
votes
3 answers

One Div animation after another using deferred object

Animate the Div after the previous Div animation has completed using deferred object. This simple method works with the two functions f1 and f2, however when I introduce f3 it fails. Is there a better way I can achieve this using the deferred…
jcoulston2
  • 83
  • 5
8
votes
2 answers

Ignoring AJAX errors with promises array and $.when

I have the following code that gets the JSON from an array of YouTube video ids. It works great when all the videos exists and the query is successful. It sends several getJSON request, and when all of them are done... the $.when.done() fires and I…
Carlos Cabo
  • 741
  • 1
  • 7
  • 14
8
votes
1 answer

Can I force jQuery Deferred/Ajax to execute fail handler after it has been resolved?

An example to make clear what i want to do. This is what I would usually do: function success(data, status, jqxhr){ if ( data.error ) return failure(jqxhr, status, data.error); // process data } function failure(jqxhr, status, err){ …
lordvlad
  • 5,200
  • 1
  • 24
  • 44
8
votes
2 answers

Nested jQuery $.when

Essentially I am tring to write this: var async1 = $.when( a1() ).then(function(){ a2() }); var async2 = $.when( a3() ).then(function(){ a4() }); $.when(async1, async2).then(function(){ console.log("complete"); }); But at the moment when a1…
Jon Wells
  • 4,191
  • 9
  • 40
  • 69
8
votes
2 answers

What does $.when do for a single $.Deferred?

I'm trying to understand $.when, and I can see that it can be useful when you want to wait for multiple deferreds before proceeding. However, I'm not sure I understand what the use-case is for using $.when with one deferred. To illustrate: var…
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
8
votes
1 answer

Javascript executes twice in Internet Explorer

I currently ran into a problem where a lazy loaded javascript would execute twice using internet explorer - and ONLY internet explorer (currently version 9). Firefox and chrome works. Here is my code: injectExternalJavaScript: function(fileUrl) { …
mayrs
  • 2,299
  • 2
  • 24
  • 35
7
votes
2 answers

JQuery deferred with .each()

Any ideas how you might use JQuery's deferred methods with a function that detects all changed forms and submits each one as an Ajax post? I can get the same thing working if I just list a load of form submissions but if I…
Kevin Monk
  • 1,434
  • 1
  • 16
  • 23
7
votes
2 answers

Catching Backbone sync errors

I needed to catch a possible login page in all responses from the server, so I have overridden Backbone.sync globally so I can check all errors before passing them on. Backbone.originalSync = Backbone.sync; Backbone.sync = function (method, model,…
d4kris
  • 528
  • 5
  • 11
7
votes
2 answers

Deferred with jQuery - when() with getJSON() callbacks

I'm trying to understand when function and deferred objects in jQuery. $.when($.getJSON('/echo/json', function () { console.log('sucess'); }, function () { console.log('error'); })).then(console.log('get JSON ready!')); This example…
Lukasz R.
  • 2,265
  • 1
  • 24
  • 22
7
votes
1 answer

Wait until promise and nested thens are complete

I'm returning a promise from a function like this: resultPromise = dgps.utils.save(opportunity, '/api/Opportunity/Save', opportunity.dirtyFlag).then(function () { self.checklist.saveChecklist(opportunity).then(function () { …
RolandG
  • 1,269
  • 4
  • 14
  • 21
7
votes
3 answers

Why does $.when().pipe().then() work, but not $.when().then().then()?

I'm still trying to wrap my head around using JQuery's Deferred objects, and am scratching my head at one particular problem. In the following code, I initially tried to chain deferred.then() but it never worked. All three functions execute at…
eterps
  • 14,198
  • 4
  • 35
  • 46
6
votes
1 answer

jQuery deferred - do I need pipes or chains to achieve this pattern?

I'm trying to implement the folowing scenario, using JQuery deferred, without much luck. What parts of the deferred api would you use, and how would you structure your calls to achieve the following: 1st ajax callA to serviceA retrieve a list of…
zadam
  • 2,416
  • 2
  • 23
  • 32