jquery-deferred

jquery deferred - wait until two calls complete

假如想象 提交于 2021-02-17 19:31:06
问题 I am looking for a way to do a callback after two ajax calls completes: $.when( call1(), call2() ).always(function() { // Here I want to be sure the two calls are done and to get their responses ); The catch is that one of the calls might fail. So, in my code the always will invoked without waiting to the other call. How can I wait for both calls to done (success or failure)? 回答1: Here is something that should do the trick: $.whenAllDone = function() { var deferreds = []; var result = $

Combine multiple jQuery Deferred objects into a new Deferred object

落爺英雄遲暮 提交于 2020-05-29 07:31:47
问题 here's the code: http://jsbin.com/lizami/edit?js,console Paste the code here as well: var aaa = $.Deferred(); var bbb = function(data){ console.log(data); var dfd = $.Deferred(); setTimeout(function(){ dfd.resolve("bbb is done"); }, 1000); return dfd.promise(); }; var ccc = function(data){ console.log(data); var dfd = $.Deferred(); setTimeout(function(){ dfd.resolve("ccc is done"); }, 1000); return dfd.promise(); }; var ddd = function(data){ console.log(data); return data; }; aaa.then([bbb

Combine multiple jQuery Deferred objects into a new Deferred object

荒凉一梦 提交于 2020-05-29 07:31:30
问题 here's the code: http://jsbin.com/lizami/edit?js,console Paste the code here as well: var aaa = $.Deferred(); var bbb = function(data){ console.log(data); var dfd = $.Deferred(); setTimeout(function(){ dfd.resolve("bbb is done"); }, 1000); return dfd.promise(); }; var ccc = function(data){ console.log(data); var dfd = $.Deferred(); setTimeout(function(){ dfd.resolve("ccc is done"); }, 1000); return dfd.promise(); }; var ddd = function(data){ console.log(data); return data; }; aaa.then([bbb

Jquery deferred call back oddness

↘锁芯ラ 提交于 2020-01-17 02:53:15
问题 I was playing around with call backs and deferred functions in jQuery and was wondering if anyone could tell me why this works http://jsfiddle.net/austinbv/QVujr/ get_each_total = function(callback) { var requests; requests = []; var url; url = "http://otter.topsy.com/search.js?callback=?&apikey=38A260E9D12A4908B1AF9184B691131&q=justin+bieber&window=d"; return requests.push($.getJSON(url, function(data) { })); return $.when.apply($, requests).then(function() { callback(); }, function() {

in JavaScript, how to wrap a promise in timeout?

喜欢而已 提交于 2020-01-12 06:48:35
问题 It's a common pattern to implement timeout of some asynchronous function, using deffered/promise: // Create a Deferred and return its Promise function timeout(funct, args, time) { var dfd = new jQuery.Deferred(); // execute asynchronous code funct.apply(null, args); // When the asynchronous code is completed, resolve the Deferred: dfd.resolve('success'); setTimeout(function() { dfd.reject('sorry'); }, time); return dfd.promise(); } Now we can execute some asynchronous function called myFunc

in JavaScript, how to wrap a promise in timeout?

拜拜、爱过 提交于 2020-01-12 06:45:07
问题 It's a common pattern to implement timeout of some asynchronous function, using deffered/promise: // Create a Deferred and return its Promise function timeout(funct, args, time) { var dfd = new jQuery.Deferred(); // execute asynchronous code funct.apply(null, args); // When the asynchronous code is completed, resolve the Deferred: dfd.resolve('success'); setTimeout(function() { dfd.reject('sorry'); }, time); return dfd.promise(); } Now we can execute some asynchronous function called myFunc

How convert Angular promise to jquery deferred object

徘徊边缘 提交于 2020-01-11 04:43:06
问题 I want to return promises from my module/sdk to non-angular javascript. For example if I'm returning promise to a jquery, I should be probably sending jquery deferred object. How can I convert an Angular promise to a jquery promise/deferred obj. Any suggestions are much appreciated. 回答1: Disclaimer : jQuery promises don't play nice with other libraries - at all . jQuery will not assimilate other third party promises on its own. Angular $q promises on the other hand - will, so whenever you

jQuery When Done on dynamically pulled function call

自闭症网瘾萝莉.ら 提交于 2020-01-06 16:23:09
问题 I have the following code: In site-code.js .... var ajaxContentFunc = $(origin).data("modal-content-handler"); $.when(window[ajaxContentFunc]()).done(function (resp) { kModal.showContent(resp); }); In another file I have the following tag and function <a href="#" data-modal-content-handler="ajaxContentGeneration">Click Me</a> .... function ajaxContentGeneration() { var aProm = $.ajax({ url: "tests/ajax/AjaxTest.aspx", data: { exampleType: "modal-ajax" }, dataType: "html" }); aProm.done

Async TypeScript function return jQuery promise

天涯浪子 提交于 2020-01-05 12:16:13
问题 I'm trying to build an MVC like controller in TypeScript and I'm having difficulty getting my async method to return a deferred promise. Here's my function signature: static async GetMatches(input: string, loc?: LatLng):JQueryPromise<any> { The compiler tells me that a 'JQueryPromise' is not a valid async function return type. I would have thought that something like this would be the most common use case for an async function but I can't find any examples. Any help? 回答1: JQueryPromise does