Questions tagged [jquery-deferred]

jQuery's deferred (also known as promises and futures) can be used to manage callback queues

jQuery.Deferred(), introduced in version 1.5, is a chainable utility object that can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.

1147 questions
0
votes
1 answer

Ignore timeouts during jQuery.when

I have some jQuery ajax requests which I am running in parallel with a .when call. I want to ignore the ones that haven't returned after their timeout period. Here is a simple form of it: var ajax1 = $.ajax({url: url1, timeout: 1000, …
explunit
  • 18,967
  • 6
  • 69
  • 94
0
votes
1 answer

Mixing a queue of callback functions and jQuery deferreds

I am trying to create a queue of functions to be called to return autocomplete results. Some of them are functions I construct myself from $.getJSON calls and some are provided to me by external developer using what's specified for jQuery UI…
0
votes
1 answer

Using $.Deferred() as a callback

in my project I'm not using callbacks instead I'm trying to use $.Deferred to have uniform logic across all application, I have lots places in my code where I do something like the following: function someMagicHandler(request) { var me = this; …
Lu4
  • 14,873
  • 15
  • 79
  • 132
0
votes
3 answers

Collect data to object with four async calls and handle the object onready

I have a handler (callback), an object to handle and four functions, which collect the data to object. In my case I wish to asynchronously call four data retrievers and when execution of all four is complete, handle the resulting object (something…
0
votes
4 answers

OOP and jQuery: how to init a var with Deferred();

This is my javascript code Its goal is only for education. I'm studying js OOP and jquery function App() { this.deviceReadyDeferred = new $.Deferred(); this.init = function() { console.log ("Run"); …
realtebo
  • 23,922
  • 37
  • 112
  • 189
0
votes
1 answer

how to use $.when in jquery with any method as a differed?

I am wondering if I can use $.when with a jquery selector or action as a deferred, like: $.when(newTemplate.appendTo("#container")).done(function(){ var rand = Math.floor((Math.random()*1000)+1); console.log(rand); }); appendTo might not be…
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337
0
votes
1 answer

jQuery $.Deferreds and $.each

Attempting to use $.Deferreds in place of setTimeOut which I was using prior. I'm running into an issue, as writer() isn't actually done, because the $.each are still looping at the time printer() is called. I haven't seen an example of $.Deferreds…
Jason
  • 7,612
  • 14
  • 77
  • 127
0
votes
3 answers

jquery deferred for async methods

I have a function that internally makes ajax call and has success and failure callback method. function dothis() { object.getMyData(x,y,successCallback,failureCallback); } the function returns immediately since getMyData is an async one . Now i…
Dav
  • 58
  • 1
  • 7
0
votes
3 answers

jQuery deferred objects: unexpected behavior with .when()s, .then()s and .done()s

I have a bunch of nested functions returning deferred objects from ajax calls. Here's what my code looks like function makeCalls() { var ajaxDfd1 = $.ajax(...); ajaxDfd1.then(function() { // want to execute after first call …
Charlotte Tan
  • 2,452
  • 2
  • 20
  • 24
0
votes
1 answer

Multiple $.getJSON requests return differently within promise

I have following code: var aReq = $.getJSON('/path/A'), bReq = $.getJSON('/path/B'); $.when(aReq, bReq).then(function(A, B) { console.log(A, B); // logs: [Array[5], "success", Object], [Array[20], "success", Object] }); Why is this wrapped…
dan-lee
  • 14,365
  • 5
  • 52
  • 77
0
votes
1 answer

Using jQuery deferred() and resolve within a function that is within a loop

I have a global var var imageURL = jQuery.Deferred(); as a deferred object. Next I have a function that runs through a loop, and for each loop I intend to get the value that is produced through an asynchronous function. The problem I had was that I…
JamesG
  • 2,018
  • 2
  • 28
  • 57
0
votes
1 answer

$.get for each item in an array of deferred objects not quite working

I have an array of object that I'm trying to iterate over and build markup for a list from. I'm using an array to store the deferred requests and $.when to inject the concatenated markup into the DOM after all the request have been completed. Here's…
jszpila
  • 676
  • 9
  • 24
0
votes
1 answer

Replace an older promise with a newer one in a jquery deferred chain

I have an object that uses jQuery's Deferred to create my own promise that I resolve after a timeout. I then chain an ajax call, and return the promise. var Obj = function() { var _obj = new $.Deferred(); setTimeout(function() { …
Elvis D'Souza
  • 2,273
  • 1
  • 23
  • 31
0
votes
1 answer

Jquery deferreds: using filters with arrays of promises

I am a client-side newbie trying to wrap my head around jQuery Deferred objects, and in particular chaining. I have the case of one promise object substituting another promise object in its filtering working: // works great. output: // about to…
Polly
  • 549
  • 5
  • 11
0
votes
3 answers

Deferred Object's Array and Index Issue

In the ajax request I need to update olist[i] with the pages returned from the ajax request. How can I make i equal the correct index so I can properly set the pages? I tried adding _index: i to ajax, but could not access it. function GetPagesList()…
user1167466
  • 333
  • 1
  • 4
  • 14