jquery-deferred

$.Deferred: How to detect when every promise has been executed

狂风中的少年 提交于 2019-11-26 02:01:55
问题 I have a number of async tasks that need to be completed, so I\'m using promises. I need to detect when each one of the promises has been executed (both resolved and rejected). I must not continue execution until that point. I was using something like this: $.when(promise1, promise2, ...).always(); But this code is wrong, because the when method has lazy evaluation, and it returns as soon as one of the promises fails. So the always callback also runs as soon as one of the promises fail. I was

How can jQuery deferred be used?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 01:40:32
问题 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 fitting them into patterns? I have already read the API and the source, so I know what it does. My question is how can we use these new features in everyday code? I have a simple example of a buffer class that calls AJAX request in order. (Next

How do you work with an array of jQuery Deferreds?

拈花ヽ惹草 提交于 2019-11-26 00:19:17
问题 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 objects are loaded, validated against the schema, and displayed. As the user CRUDs the data, the schemas provide first-pass validation. I\'m having a problem with initialization. I use an Ajax call to fetch the root object, $.when(), and then create an

jQuery Deferred - waiting for multiple AJAX requests to finish [duplicate]

偶尔善良 提交于 2019-11-25 23:49:21
问题 This question already has answers here : Pass in an array of Deferreds to $.when() (9 answers) Closed 5 years ago . 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 ajax requests (possibly hundreds) at once and need to defer until all of them are done. I can\'t rely on the last one being done

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

自作多情 提交于 2019-11-25 23:22:25
问题 @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 promises. I walk away from Domenic\'s article feeling that jQuery promises have an inherent failing, conceptually. I am trying to put examples to the concept. I gather there are two concerns with the jQuery implementation: 1. The .then method is not

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

倖福魔咒の 提交于 2019-11-25 23:10:01
问题 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 does .then() as all the callbacks are all invoked on a completion of a successful operation. Can anyone please enlighten me to the correct usage? 回答1: The callbacks attached to done() will be fired when the deferred is resolved. The callbacks

Pass in an array of Deferreds to $.when()

点点圈 提交于 2019-11-25 21:53:22
问题 Here\'s an contrived example of what\'s going on: http://jsfiddle.net/adamjford/YNGcm/20/ HTML: <a href=\"#\">Click me!</a> <div></div> JavaScript: function getSomeDeferredStuff() { var deferreds = []; var i = 1; for (i = 1; i <= 10; i++) { var count = i; deferreds.push( $.post(\'/echo/html/\', { html: \"<p>Task #\" + count + \" complete.\", delay: count }).success(function(data) { $(\"div\").append(data); })); } return deferreds; } $(function() { $(\"a\").click(function() { var deferreds =