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
0
votes
1 answer

Deferred.state to change css properties

Right, I've got this code here: var dfd1 = $.Deferred(); var dfd2 = $.Deferred(); $( "#draggable" ).draggable({ revert: "invalid", snap: "#droppable", }); $( "#droppable" ).droppable({ accept:…
rudolf
  • 61
  • 1
  • 7
0
votes
1 answer

jQuery.When always calls fail

I'm using jQuery.when to make two ajax requests, looking at firebug the requests are being made and seem to return the correct data with a status code of 200 but the fail callback is being executed instead of the done callback. what am I doing…
Dave
  • 3,812
  • 5
  • 31
  • 39
0
votes
1 answer

Multiple doneCallbacks in Deferred then

The documentation for deferred.then() states that doneCallbacks is A function, or array of functions, called when the Deferred is resolved. When I write either .then(new Array(getData2, showDiv)) or .then([getData2, showDiv]) none of them…
Carl R
  • 8,104
  • 5
  • 48
  • 80
0
votes
1 answer

Wrapping $.get in another deferred

I'm just trying to get my head around the details of deferred. Why doesn't the following make the two calls syncronous? http://jsfiddle.net/JSw5y/889/ Console output: Running ajax get Fading in Fading in done Finished running ajax get Desired…
Carl R
  • 8,104
  • 5
  • 48
  • 80
0
votes
1 answer

jQuery defered/promise/animation with CoffeeScript

I have three things I would like to animate: the head, the feet, and the arm. I'm using jQuery and CoffeeScript. I would like to create a function that animates the head and feet like this: move_feet: () -> feet.animate({ left: 100 …
Alexis
  • 23,545
  • 19
  • 104
  • 143
0
votes
1 answer

How do I use jQuery deferred objects with jQuery UI tabs?

I am encountering some issues with integrating jQuery deferred objects with jQuery UI tabs. Basically, I want to achieve something like this: (function($) { var tabs; function func1 () { return $.get(url, function() { // ajax…
Sachin
  • 2,667
  • 9
  • 35
  • 39
0
votes
1 answer

using jquery's deferred with settimeout

I have a module that has an internal loop (using 'settimeout'). I want to fire a callback each time the timer happens. I tried using jQuery's deferred object with no luck.. Something like: $(function(){ var module = new MyModule(); …
Yaniv Efraim
  • 6,633
  • 7
  • 53
  • 96
0
votes
1 answer

jQuery: promises: 'always()' not executing

I am having trouble getting always() to fire on my Deferred in jQuery. done() and fail() work fine, but somehow I must be doing something wrong, because always() never fires. With $.when it works... var Validator = { validate_something:…
Joseph Tura
  • 6,290
  • 8
  • 47
  • 73
0
votes
2 answers

synchronizing deferreds with when

I've trouble synchronizing finished Deferreds with $.when(). I want to be notified when all deferred are finished wether resolved or failed. My problem is when().always() that fires at first fail and doesn't wait other deferred to complete. Not sure…
BiAiB
  • 12,932
  • 10
  • 43
  • 63
0
votes
0 answers

How to "pause" a Javascript loop waiting for user action

I have a loop and upon certain condition I am trying to have a Jquery deferred object to wait for user input before continuing or breaking the loop. If I place the confirm().then(block before the function confirm(){ it tells me that there are not…
Gian
  • 549
  • 3
  • 7
  • 18
0
votes
2 answers

Wait for the first of multiple jQuery Deferreds to be resolved?

With jQuery I know that I can use $.when() to wait for all of multipe Deferreds to be resolved. (Or for the first one to be rejected.) But is there a simple way to fire of multiple Deferreds and then just wait for the first one to be resolved? For…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
0
votes
1 answer

jQuery Deferred & console.log - Strange behavior

Consider the following example: var $_dfd = $.Deferred(), $_x = {}; $_x = { a: 1, b: 2 }; console.log($_x); // Gives {a: 1, b: 2, more: {c: 3, d: 4}} <== Weirdness here console.log($_x.a); // Gives 1 console.log($_x.more); // Gives…
gsklee
  • 4,774
  • 4
  • 39
  • 55
0
votes
1 answer

Using $.when to combine promises

I am learning how to use jQuery's deferred, so I made a simple little example, so I could mess around. function a() { var d = new $.Deferred, $A = $('#A'), $P = $('#P').progressbar(); setTimeout(function() { …
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
0
votes
1 answer

jQuery Deferred - Variable scope in deferred getJSON success functions

I am adding deferred getJSON calls to an array inside a for loop that reference local variables inside their success function. The problem I am having is that when the success function is called, the local variable is taking the value from the last…
Mitch Satchwell
  • 4,770
  • 2
  • 24
  • 31
0
votes
1 answer

jQuery Deferreds with Chained Saves, Unified Result

I have two objects, ObjectA and ObjectB. I want to save ObjectB only after ObjectA is done, but I want to return a promise which wraps the result of both of them. Here's my first hack at it to show the functionality that I want. This function…
Adam Terlson
  • 12,610
  • 4
  • 42
  • 63