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

jQuery jqXHR - cancel chained calls, trigger error chain

I am creating a ajax utility for interfacing with my server methods. I would like to leverage jQuery 1.5+ deferred methods from the object returned from the jQuery.ajax() call. The situation is following. The serverside method always returns a JSON…
m0sa
  • 10,712
  • 4
  • 44
  • 91
15
votes
4 answers

Is it possible to reset a jQuery deferred object state?

Is it possible to reset a resolved jQuery object to an 'unresolved' state and kick off it's initialization and callbacks all over again? The specific thing I'm doing is that I have a jQuery deferred wrapper over the local file system api. From there…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
15
votes
8 answers

Deferred/Promise pattern in C++

I've recently discovered, and fallen in love with, the Deferred/Promise pattern used in jQuery. It just encapsulates so many async use cases, including the wonderful chaining, filtering ability, that I can't believe I missed it for so long. I've…
Shane
  • 3,051
  • 3
  • 40
  • 45
14
votes
3 answers

How to use jQuery's deferred object with custom javascript objects?

I have a standard javascript object whose prototype is extended with a .start() method taking 2 callbacks as arguments: success and failure respectively. This method performs some asynchronous processing (it's not AJAX) and depending on the result…
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
14
votes
3 answers

javascript function wait until another function to finish

I have two javascript functions that are called from android. After long debug sessions finally I realized that the problem is arising from the fact that second function is getting called before first one is finished. I already searched the examples…
tugce
  • 651
  • 3
  • 13
  • 28
14
votes
2 answers

jquery custom deferred functions

I have three functions i'm trying to run, the first two are doing some async stuff that need data for the third to use. I want the third function to fire only when 1 and 2 are both done. this is the general structure but the final function is firing…
Brian
  • 4,328
  • 13
  • 58
  • 103
14
votes
2 answers

jQuery deferred : use to delay return of function until async call within function complete + get return value

How can I correctly use jQuery deferreds to delay return of function until async call within function complete + get return value? This is my current code: function getFields(page) { var dff = $.Deferred(); result = {}; $.ajax( //the async…
bguiz
  • 27,371
  • 47
  • 154
  • 243
14
votes
4 answers

IcedCoffeeScript or jQuery deferred

Recently while working on a Backbone.JS/jQuery/CoffeeScript project, I found myself in a mess of callback and timing issues. I needed to wait for something to complete before proceeding and found myself in a mess of nested callbacks ... which is…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
13
votes
2 answers

Javascript Promise vs jQuery Deferred

What are the pros & cons of Javascript Promises vs jQuery Deferred Objects? For example, what issues do they each have, if any? A fellow stack overflow member stated: "...real promises are real, and fake promises are fake." What did he mean by…
picokol
  • 174
  • 1
  • 10
13
votes
4 answers

jQuery.when() progress for array of Deferred and/or Promise

I'm using jQuery's .when() to wrap an array of promises so that I can do some action when all promises have been resolved. $.when.apply($, requests).done(function () { console.log(arguments); //it is an array like object which can be looped …
Brad
  • 159,648
  • 54
  • 349
  • 530
13
votes
1 answer

Is any jQuery version compliant to Promise/A specifications?

After going through several articles I have come to know that promise implementation is there in jQuery. But I am not sure whether any version of jQuery is Promise/A compliant or not.
13
votes
2 answers

jQuery Waiting for Multiple Events to fire

Is it possible to "wait" for multiple events before executing a function? I know its possible with jQuery deferred obejcts to use $.when to wait for two promises to resolve but I wondered if its possible with just plain old events? Lets say a…
Jon Wells
  • 4,191
  • 9
  • 40
  • 69
13
votes
2 answers

Chain of Jquery Promises

I have a simple chain of events: Get Columns from a metaData table (async) load selected columns (async) render list I used to just the chain these functions, each calling the next when it had completed. However, its not very obvious what's…
Jon Wells
  • 4,191
  • 9
  • 40
  • 69
13
votes
1 answer

Throwing an Error in jQuery's Deferred object

I have an $.ajax promise and want to check whether my (syntactically valid) response contains an error, triggering the rejected status in that case. I have worked with my own promise library which deals such tasks easily. I do not really like…
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
12
votes
7 answers

Chaining ajax requests with jQuery's deferred

I have a web app which must call the server multiple times. So far, I had a long nested callback chain; but I would like to use jQuery's when,then etc. functionality. However, I can't seem to get stuff running again after using a then. $ .when…
Anteru
  • 19,042
  • 12
  • 77
  • 121