Menu
  • HOME
  • TAGS

jQuery deferred - when multiple timeout tasks have completed

javascript,jquery,jquery-deferred,deferred,.when

The problem is, you need to return promise from the start method return { other: function () {}, start: function () { var dfd = $.Deferred(); el.filter.animate({ "opacity": "0.6", "filter": "alpha(opacity=60)" }, 2000, "easeInOutCirc", function () { el.share.removeClass('fa-spin'); setTimeout(function () { el.share.removeClass('fa-cog').addClass('fa-bars'); }, 1000); setTimeout(function () { el.scroll.animate({ "opacity": "1",...

How to tell when multiple functions have completed with jQuery deferred

javascript,jquery,ajax,deferred,.when

You need to first make each of these functions return the deferred object jQuery gives you when you make an AJAX request. Then you can put those in to an array, and apply that to $.when(). Something like this: var deferreds = []; $.ajax({ url: url, cache: false, beforeSend: function(){...

jQuery do something WHEN an event happens

jquery,if-statement,addclass,.when

Check if Scroll is greater than or equal to ScrollFXfullHeight, then check if your element already has the class fixed. If not, add it: if (Scroll >= ScrollFXfullHeight) { if(!$("#navigation, .hidden_menu_link_container").hasClass('fixed')) { $("#navigation, .hidden_menu_link_container").addClass("fixed"); } $("#navigation, .hidden_menu_link_container, .stop_the_jump").addClass("thinner"); } This way, even if the user scrolls past that exact point,...

$.when.apply.done not executing asynchronous functions

javascript,jquery,ajax,asynchronous,.when

Your anonymous function has no return so its effective return value is undefined. So, first you need to fix your anonymous function to include a return: functions.push(function() { return $.ajax(...); }); You can also make a cleaner implementation of your invocation loop: var requests = functions.map(function(f) { return f(); });...

When and Deferred

javascript,jquery,each,.when

Use $.map instead of $.each. This returns an array of the Deferred objects returned by your iteration function, and these can then be passed to $.when. $.when.apply(null, $.map(function(index, file) { return self.fileRead.read(file).done(function(fileB64) { self.fileShow(file, fileB64, fileTemplate); }); })).done(function() { console.log('done'); }); ...

group_concat in mysql with “case when ” conditions

mysql,case,concat,group-concat,.when

The syntax you used for the CASE expression is not correct, you can only select one expression inside the case expression, but you selected more than one column, and I noticed that only one columns you need to select based on the case condition, so I moved all the columns...

How to use jQuery.when() with an array of URLs?

jquery,jquery-deferred,.when

You'd use .apply and then get it with arguments: var urls = [ '/url/to/script1.js', '/url/to/script2.js', '/url/to/script3.js', '/url/to/script4.js' ]; var requests = urls.map(function(url){ return $.getScript(url); }); $.when.apply($, requests).then(function(){ console.log(arguments); // logs all results, arguments is the results here return [].slice.call(arguments); }).then(function(arr){ // access as an array }); ...

Javascript: Is there a way to specify infinite input parameters for Parse.Promise.when?

javascript,parse.com,promise,.when

No, but there will be. ECMAScript 6 features rest parameters which allow you to do this: Parse.Promise.when(promises).then(function(r1, r2, r3, ....rest) { console.log(r1); // prints 1 console.log(rest); // an array with the rest of the parameters. }); In EcmaScript 5 you need to use arguments: Parse.Promise.when(promises).then(function() { console.log(arguments[0]); // prints 1...

Wait until all ajax queries in each() function are finished using $.when()

jquery,ajax,.when

Ok, I found it! var resp_error = false; var ajax_calls = []; $(".items").each(function() { ajax_calls.push(ajax_item($(this)).done(function(resp){ if (resp.val == 0) return (resp_error = true); })); }); $.when.apply($, ajax_calls).then(function() { if (!resp_error) callback(); }); ...

$.when with arrays of functions is not working properly

jquery,ajax,jquery-deferred,.when

$.when does not accept or expect an array of functions, it expects an array of deferreds. You need to invoke your functions, and pass the promises in. var topPriorityPromises = []; topPriorityFunctions.push(showDiv()); topPriorityFunctions.push(getData()); $.when.apply($, topPriorityPromises ).then(function () { // ... If you simplify this and ignore the array/apply portions, you...