.when

Using an array of deffered with jQuery.when()

微笑、不失礼 提交于 2019-12-08 06:22:32
问题 I'm using $.when to run 2 functions prior to some other logic. Now, in several cases I need to run a different set of functions prior to doing that same logic, so I wanted to pass an array of the functions to $.when , but couldn't make it run. Something like: function funcA(){ console.log("funcA"); } function funcB(){ console.log("funcB") } var funcArr = [funcA, funcB]; $.when(funcArr).then(function(){ console.log("DONE!"); }); But this doesn't work and the only thing written to the console

How to tell when multiple functions have completed with jQuery deferred

梦想与她 提交于 2019-12-08 04:13:14
问题 I have 3 functions which handle data pulled in from AJAX, they update the page after the ajax function is called. When the AJAX function is called I show a loader, I want to hide the loader after the AJAX has completed and the functions have completed. How can I use deferred with when and then in jQuery to test once all 3 function are completed. Here is my AJAX code, this hides the loader on AJAX success at the moment, ideally this would be after the 3 functions have been completed / were

How to tell when multiple functions have completed with jQuery deferred

主宰稳场 提交于 2019-12-06 15:26:18
I have 3 functions which handle data pulled in from AJAX, they update the page after the ajax function is called. When the AJAX function is called I show a loader, I want to hide the loader after the AJAX has completed and the functions have completed. How can I use deferred with when and then in jQuery to test once all 3 function are completed. Here is my AJAX code, this hides the loader on AJAX success at the moment, ideally this would be after the 3 functions have been completed / were successful. The 3 functions receive data to process and display on the page, they are not AJAX functions.

$.when.done callback isn't working

被刻印的时光 ゝ 提交于 2019-12-04 18:39:39
The following code has a bad syntax error. Probably because I'm using 'for' or something. $.when( for (var i=0; i < 5; i++) { $.getScript( "'" + someArr[i].fileName + ".js'"); } $.Deferred(function( deferred ) { $( deferred.resolve ); }) ).done(function() { alert("done"); }); I'm trying to call couple of scripts and then when trey are all loaded I want to an alert to show. A commented (but untested) solution with the changes is below // When takes a promise (or list of promises), not a random string of javascript $.when((function() { // First we need to define a self resolving promise to chain

Can I pass Promises to jQuery.when(), or only Deferreds?

旧城冷巷雨未停 提交于 2019-12-04 03:46:25
问题 The documentation for jQuery.when() says that this function takes Deferreds. However, it also says later on that: If a single argument is passed to jQuery.when() and it is not a Deferred or a Promise... which seems to imply that it can take Promises as well. But Promises are not Deferreds - they have a subset of the Deferred's methods. I guess you could say that a Deferred is a Promise, but a Promise is not a Deferred. Questions: Can $.when() take either Promises or Deferreds? This seems to

$.when not waiting for Ajax request to finish

与世无争的帅哥 提交于 2019-12-02 18:07:02
问题 I want to first render a view with Backbone.js that displays an Article pulled from the server. I then want to mark this as "seen" and return the count of unseen messages to the router as it needs to be made available to other views. So in my Router, I have: getArticle: function (id) { require(["app/models/article", "app/views/Article"], function (models, Article) { var article = new models.Article({id: id}); article.fetch({ success: function (data) { var articleView = new Article({model:

$.when not waiting for Ajax request to finish

折月煮酒 提交于 2019-12-02 10:14:29
I want to first render a view with Backbone.js that displays an Article pulled from the server. I then want to mark this as "seen" and return the count of unseen messages to the router as it needs to be made available to other views. So in my Router, I have: getArticle: function (id) { require(["app/models/article", "app/views/Article"], function (models, Article) { var article = new models.Article({id: id}); article.fetch({ success: function (data) { var articleView = new Article({model: data, message_count:that.message_count}); slider.slidePage(articleView.$el); $.when(articleView.saveView()

Can I pass Promises to jQuery.when(), or only Deferreds?

家住魔仙堡 提交于 2019-12-01 21:05:31
The documentation for jQuery.when() says that this function takes Deferreds. However, it also says later on that: If a single argument is passed to jQuery.when() and it is not a Deferred or a Promise... which seems to imply that it can take Promises as well. But Promises are not Deferreds - they have a subset of the Deferred's methods. I guess you could say that a Deferred is a Promise, but a Promise is not a Deferred. Questions: Can $.when() take either Promises or Deferreds? This seems to work in my testing. Is there a bug in the doc? I think it should say that $.when() takes Promises, not

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

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 =