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

Get SignalR To Raise JQuery Deferred Fail Event

I am trying to determine how to get SignalR to properly raise the fail method of a jQuery deferred. Currently I am achieving this as follows" public void JoinChat(string username) { var user = userRepo.getUser(username); if(user == null) { …
msarchet
  • 15,104
  • 2
  • 43
  • 66
0
votes
3 answers

How do I pause resolution of a jQuery deferred in the middle of a chain?

I am trying to force a serialized logic onto a set of asynchronous activities on a webpage. I am fairly certain I want to use the jQuery deferred object, but I run into the problem that the functions I want to execute are dependent on when the user…
D. G.
  • 451
  • 3
  • 11
0
votes
1 answer

execute done callback of jquery $.when() once (in backbone-js app)

I'm looking for a way to "unbind" jQuery's $.when() after the .done() callback has been executed a single time, analogous to using jQuery's .one() instead of .on() for a single event. The reason why I am using deferred objects instead of events in…
adekom
  • 216
  • 2
  • 10
0
votes
2 answers

Make two jQuery AJAX calls and get context for both, even if one fails

I'd like two make two AJAX requests for data. One or both of the requests may fail. In that case I still would like to interact with the data from both requests (or the successful request). If I do something like: $.when($.get("page1"),…
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
0
votes
2 answers

jQuery 1.8: Ajax beforeSend prevents deferred.done() from executing

If you execute this code in 1.7, the alert appears and 1.8 it does not: $.when( $.ajax({ url: "whatever", dataType: "json", beforeSend: function(jqXHR, settings) { return false; } })).done(function(a1) { alert("this…
Dave L.
  • 9,595
  • 7
  • 43
  • 69
0
votes
2 answers

How to properly utilize jQuery Deferred/promise on auto-invoked function such as .ajax()'s beforeSend()?

I'm working on extending jQuery's ajaxPrefilter interface to add additional functionality to AJAX calls; namely tacking header data onto the XHR request using setRequestHeader() within the beforeSend() method. The thing is, both the ajaxPrefilter…
J. Ky Marsh
  • 2,465
  • 3
  • 26
  • 32
0
votes
1 answer

Unable to reject jquery deferred with a piped function if it was resolved by a previous pipe

The code is pretty straight foreword: var handleNextPressedDeferred = $.Deferred(); $('input:button').live('click',function(){ console.log('resolving'); return handleNextPressedDeferred.resolve(); }); …
0
votes
1 answer

Is this the correct use of $.Deferred in this situation?

I have the following code withhn a module var def = $.Deferred(); $.getJSON("http://localhost:62588/api/Values/getXMLData") .done(function(json){ def.resolve($.parseJSON(json)); }); return def; I then have to call it from another module so…
davy
  • 4,474
  • 10
  • 48
  • 71
0
votes
1 answer

Constructing jquery's deferred object when parameters programatically

I'm new to javascript and jquery, and I'm learning how to use jquery's Deferred object to wait for a loop to complete before performing an action. The functions inside the loop don't need to be called in any special order. In other words, function n…
Polly
  • 549
  • 5
  • 11
0
votes
1 answer

how to use jquery deferred with vktemplate / queuing ajax requests

Using vktemplate isn't quite working when I try to use jquery deferreds. Since the vktemplate makes an ajax call of its own, the deferred gets resolved before vktemplate completes its work, and its optional callback. How can I set up vk so that the…
1252748
  • 14,597
  • 32
  • 109
  • 229
0
votes
1 answer

code under jquery done() executes before when()

Why does the code under the done() statement execute before the other 3 function which are called under when()? It goes immediately. I thought when was used to queue up functions and done was used to execute something when the when code was, well,…
1252748
  • 14,597
  • 32
  • 109
  • 229
0
votes
1 answer

printing html and json results with jquery then()

I'm trying to learn to use jquery deferreds. When using html on jsfiddle, I get an object returned that when printed in the then() statement, has two lines: "success" and the html that is returned by the ajax request. So that when I do…
1252748
  • 14,597
  • 32
  • 109
  • 229
0
votes
1 answer

If deferred state is resolved, when is rejected

var promise = $.when(sba_dfd.promise(), sbb_dfd.promise(), sbc_dfd.promise(), sbd_dfd.promise(), sbe_dfd.promise()); if (sbf_dfd.state() || sbg_dfd.state() == "resolved") {promise.state()=="rejected"}; What is worng in this statement? I guess it's…
rudolf
  • 61
  • 1
  • 7
0
votes
1 answer

jquery click not working

var sba_dfd = $.Deferred(); /*and so on*/ $("#sbas").click(function(){ $(this).css('background-color','#ed1c24'); sba_dfd.resolve(); }); /*and on*/ $(".x").click(function(){ var promise = $.when(sba_dfd.promise()/*and on*/); …
rudolf
  • 61
  • 1
  • 7
0
votes
1 answer

Using deferred with jquery ajax calls and async processes along with user confirmation reading in between

Background This is in continuation to my question Correct way to set up a sequence of synchronous/asynchronous functions all of which can stop form submission and further processing? I got the answer on what was the correct way (deferred pipe), but…
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144