jquery-deferred

Get response of multiple deferred objects in jquery

孤者浪人 提交于 2019-12-11 13:07:43
问题 Below are my Multiple ajax calls with promises. $(window).load(function(){ $.when(getApiModemList()).done(function(vendors){ var deferreds = calculateApiBalances(vendors); $.when.apply($,deferreds).done(function(balance) { console.log(balance); console.log("All Done"); }); }); function getApiModemList(){ return $.getJSON("url"); } function calculateApiBalances(vendors) { var defer=[]; $.each(vendors,function(k,v){ defer.push($.getJSON(someurl)); }); return defer; } }); Function

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

自闭症网瘾萝莉.ら 提交于 2019-12-11 11:56:39
问题 How would i have to change this example $.when( $.getScript( "/mypath/myscript1.js" ), $.getScript( "/mypath/myscript2.js" ), $.getScript( "/mypath/myscript3.js" ), $.Deferred(function( deferred ){ $( deferred.resolve ); }) ).done(function() { //place your code here, the scripts are all loaded }); when i don't know the exact number of scripts to load and use an array of URLs instead? var urls = [ '/url/to/script1.js', '/url/to/script2.js', '/url/to/script3.js', '/url/to/script4.js' ]; As the

Jquery Deferred for an async function

安稳与你 提交于 2019-12-11 11:49:17
问题 I have been reading a lot about JQuery's deferred object. And I can see how it works to de-couple code. I wrote this orignally using Async.js but would was recommended to use promise. Most examples I find just chain things to AJAX calls. I want to chain an async function but can't figure out how to do it. I am retrieving a time from the database then using that time as a parameter in a url, finally I would then like to make a AJAX call. This is where I'm at: var fetch = function (contactId,

for loop a function with deferred

心已入冬 提交于 2019-12-11 11:18:43
问题 I have a simple function to display a console message with an item name. Something simple like: for(var i =0; i< array.length; i++) child(array[i]); var child = function(itemname){ console.log(itemname); } Here length of array is dynamic and so are the values it contains. Now I want to add some animation inside the child function and definitely want it to finish first before it gets called again by the for loop. I know how to use jQuery Deferred and can call one function after finishing other

Jquery deferred and promises

与世无争的帅哥 提交于 2019-12-11 10:04:08
问题 I am new to jquery deferred and promises. I am trying to do this var maxRes=function() { var deferred=$.Deferred(); $("<img/>").attr("src", newurl).load(function(){ s = {w:this.width, h:this.height}; imgHeight = this.height ; deferred.resolve(); }); return deferred.promise; } maxRes().done(function(){ if(imgHeight >=720) { temp="...[HD]" } else { temp = "..."; } console.log(temp); }); I keep getting this error: Uncaught TypeError: Object function (a){return null!=a?n.extend(a,d):d} has no

Dojo using deferred functions to get data in ajax callback function

流过昼夜 提交于 2019-12-11 09:48:40
问题 I have a function with a return however in the function there is an async request which holds the value that is suppose to be returned by the function. I understand with the nature of async request the function will complete and not return a value while waiting on the async function to complete. I attempted to use dojo deferred functions to have my function PostInformation() to return a value within the ajax request callback. I am having some issues and i am not sure where my issue is. Under

jQuery Ajax Wait Each Function

两盒软妹~` 提交于 2019-12-11 04:08:44
问题 $xy('#simpan').click(function() { $xy('input[id="cekbok[]"]:checked').each(function() { var data = (this.value); var div = (this.value); var str = window.location.href; var res = str.replace("wp-admin/options-general.php?page=katalogu-options", "/wp-content/plugins/katalog/includes/img/loading.gif"); var loading = ('<img src="'+res+'">') ; $xy.ajax({ type : 'POST', url : '../wp-content/plugins/katalogunique/proses2.php', data: { id : (this.value) }, success:function (data) { $xy('#result'+div

jQuery - .always() callback firing too soon

人走茶凉 提交于 2019-12-11 01:59:35
问题 I'm working on a client-side JS app which is supposed to read a CSV file, make a few API calls per row, then write the results back out to CSV. The part I'm stuck on is how to orchestrate the requests and fire off a function when all are complete. This is what I have so far: var requests = []; // loop through rows addresses.forEach(function (address, i) { // make request var addressRequest = $.ajax({ dataType: 'json', url: 'http://api.com/addresses/' + address, success: function (data,

Why is my Jquery ajax success handler being called with an array (and not the response object)

最后都变了- 提交于 2019-12-11 01:34:27
问题 I have a function which makes two rest calls to the google spreadsheetAPI. I use a $.when to make sure that the data fron thefirst call is process before dealing with the data from the second call. The problem is that the first ajax handler(getRealNames), receives a javascript object as its argument, but the second handler(displayTeams), receives an array, the 0th element is the object I was expecting to get. Why does one get an object and the other get an array? They are calling the same

How to use jQuery Deferred (when/then, etc.) to fix asynchroneous pyramid of doom issue

余生颓废 提交于 2019-12-11 01:08:37
问题 I've been puzzling for quite a while trying to wrap my head around JavaScript promises. I want to fix some issues with asynchroneous calls in my code, to de-spagethise it. But I'd love for an expert to help me, because I've wasted quite some time already. I want to use the jQuery Deferreds for it, since I'm using jQuery (v1.11) in my project already, and I don't want to add any more libraries (already have over 5). I read that the jQuery doesn't fully follow the Promises/A spec, but I figured