FAQ Database Discussion Community


Is there a way to go from Jquery Deferred/Promise to When-JS Promise

javascript,promise,jquery-deferred,es6-promise,when-js
I would like to use When-JS capability out of the promise returned by a jquery ajax call. Is there a conversion scheme ? Edit 1 https://github.com/cujojs/when/blob/master/docs/api.md#api...

$.when apparently ignored

javascript,backbone.js,marionette,jquery-deferred
I have a Compositeview that represents a list of tasks with a header that contains a counter for the tasks in such list. I have defined an ui hash for the counter to deal with it and to properly initialize it: The view: ui: { counter: "#counter", }, onRender: function(){...

jQuery deferred/promise with SPService library

jquery,jquery-deferred,spservices
I'm trying to get my promise item from SPService SPGetListItemsJson. The issue is that when SPGetListItemsJson is invoked and when requestPromise is done and the deferred is resolve, I would expect the data to pass into my anonymously function in populateDropDownControlWithList but its undefined. function populateDropDownControlWithList(option, control, addSelectValue) { if...

Implementing a fallback using promises

javascript,jquery,promise,jquery-deferred
it is a common pattern that we cascade across a list of sources of data with the first success breaking the chain like this: var data = getData1(); if (!data) data = getData2(); if (!data) data = getData3(); et cetera. if the getDataN() functions are asynchronous, however, it leads us...

jQuery deferred AJAX call return value

javascript,jquery,ajax,google-chrome,jquery-deferred
I have a function, which will either return a cached template or if the template has not been cached - it will load it via AJAX and then return it. Here's what I've got: var getTpl = function( name ) { var cached = cache.get( 'templates' ) || {}; if(...

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

jquery,jquery-deferred,.when
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...

Javascript scope/hoisting OR promises/deferreds?

javascript,jquery,ajax,jquery-deferred,hoisting
I am trying to make an external AJAX call to an API within a Jquery each loop. Here is the code I have so far. getStylesInfo(tmpMake, tmpModel, tmpModelYear, tmpSubmodel).done(function(data){ var holder = []; $.each(styles, function(index, value) { var tempValue = value; var temp = getNavigationInfo(value.id); $.when(temp).done(function(){ if(arguments[0].equipmentCount == 1){ holder.push(tempValue);...

jQuery - .always() callback firing too soon

javascript,jquery,jquery-deferred
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....

How do I create a jQuery plugin extending $.Deferred?

jquery,jquery-plugins,jquery-deferred
I want to extend $.Deferred with a new method which is supposed to have a signature similar to Deferred.fail(). What is the best way of doing that?

Encapsulating a ajax call in a deferred object and allow an abort

jquery,jquery-deferred
I'm trying to create a global ajax call that takes care of a some global functionality, for example: json { Data : { /* some object returned */ }, RedirectTo: "", // for example: "/Account/Login" ErrorMessage: "", // for example: "You have been logged out do to inactivity. } jquery...

jQuery 2.1 | Defering function until external scripts are manually loaded

jquery,jquery-deferred,youtube-data-api
Here's my dilemma: A browser hard refresh empties the browser cache, and when that happens while internet connection is lost, I cannot use my app when the internet connection resumes. I therefore want to manually (seamlessly) reload Google's client.js script and related Youtube APIv3 via a button. Is there a...

Return an empty promise

javascript,jquery,ajax,typescript,jquery-deferred
I have a function that returns a jQuery promise. It looks like this: addBooks(books: Array<Books>) { return $.ajax({ url: '/Books/AddBooks/', type: 'POST', data: ko.toJSON(books), contentType: 'application/json' }); } I do this so I can reuse this function and chain promise callbacks like: addBooks.done(() => { alert("Books added!"); }) My question...

Clojure's equlivalent to a jQuery Deferred?

jquery,clojure,promise,jquery-deferred
Clojure has promise, future, delay, etc. but none are semantically similar to a Deferred object in jQuery. They generally block if dereferenced before the value is available. Deferred objects utilize callbacks. What does Clojure (not ClojureScript) itself offer that is similar to a jQuery Deferred?

Execute Thenable Functions after Deferred Object Resolves

javascript,jquery,promise,jquery-deferred
How can a function returning a promise be run after functions returning Deferred.promise()? I have an example of the problem on JSFiddle. The alert messages are intended to end with "executed third?" as opposed to that alert displaying in the middle of the "executed first?" and "executed second?" alert messages....

$.when with arrays of functions is not working properly

jquery,ajax,jquery-deferred,.when
Problem that I'm trying to solve: I want to have two arrays of ajax functions. One with topPriority that should run first, and another one with low priority that will start as soon as ALL of the topPriority calls are done. However, this functions are not even called in the...

Will deferred block the UI if used with synchronous function?

javascript,jquery,jquery-deferred
I just find out about the JQuery deferred object and those are very handy for chaining asychronous calls. Knowing that sychronous calls may also be handled by deferred, I'm wondering if it's the purpose of the deferred to give the hand back to the UI after resolving each deferred or...

delay for jquery promises

jquery,promise,jquery-deferred
I cannot find delay or wait function for jQuery promises. I have found one function on the SO (Using jQuery.Deferred to avoid nested setTimeout callbacks): function delay(time) { return function () { console.log("Delaying"); var ret = new $.Deferred(); setTimeout(function () { ret.resolve(); }, time); return ret; }; } And, it's...

jQuery deferred - when multiple timeout tasks have completed

javascript,jquery,jquery-deferred,deferred,.when
Having a few teething problems with $.deferred, $.when and $.done. I'm calling a method which has a couple of tasks inside on a timer. I'm looking at getting a callback when everything inside this method has completed, including the stuff in timers, so started looking at $.when() and $.done() to...

Unexpected deferred object's behaviour

javascript,jquery,jquery-deferred
Could anyoune please clarify what's wrong with the code below ( have read a lot of docs and examples, but still got no idea what's going on) function t() { var d = $.Deferred(); setTimeout(function(){ d.resolve(); }, 5000); return d.promise(); } function test() { var dd = $.Deferred(); $.ajax("/echo/json/").done(function() {...

jquery deferred in for loop

javascript,jquery,google-maps,jquery-deferred
So I have been working on jquery deferred but am having trouble when retrieving data in a loop. The deferred portion seems to only process the data from the final iteration. If there is only one item in the array, it fails as well, so I am not sure what...

how to execute javascript deferred sequentially?

jquery,jquery-deferred
I'm wondering if there is a way to execute deferred task sequentially and conditionally. That is, i would like to perform some asynchronous task in sequence, where i would only execute the next one depending on the result of the preceding one. The result of the chain of promise should...

Confused about JQuery promises

jquery,promise,jquery-deferred
I'm really trying hard to understand the behavior or JQuery's promise(). I want to do 3 (unrelated, but back-to-back) AJAX queries : 1. GET the user data 2. POST an image 3. POST another image Then, I'm doing a load of things that are based on then results of said...

Multiple Promise Chains in Single Function

javascript,jquery,ajax,jquery-deferred
I have some code that will dynamically generate an AJAX request based off a scenario that I'm retrieving via an AJAX request to a server. The idea is that: A server provides a "Scenario" for me to generate an AJAX Request. I generate an AJAX Request based off the Scenario....

Making multi callback synchronized with jQuery $.when

javascript,jquery,asynchronous,synchronization,jquery-deferred
This is my sample code: function out(msg) { $('#output').append(msg + '<br>'); } var myDeferred = []; $.each([8, 3, 4, 6, 9, 15, 7, 1], function (index, time) { myDeferred.push($.Deferred(function(dfd) { setTimeout(function () { out(time); dfd.resolve(); }, time * 1000); }).promise()); }); $.when.apply($, myDeferred).then(function () { out('all is done'); }); <script...

jQuery Ajax Wait Each Function

javascript,jquery,ajax,promise,jquery-deferred
$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).empty();...

jQuery deferred array not triggering .done() as expected

javascript,jquery,ajax,jquery-deferred
I'm having some trouble with jQuery deferreds. Here's my code: function makeAjaxCalls(purge){ var deferreds = []; // delete the documents _.each(purge, function(element, index, list){ console.log('purging '+element.model+' id='+element.id); deferreds.push( $.ajax({ type: 'DELETE', url: '/API/admin/purge/'+element.model+'/'+element.id }) ); }); console.log('returning array with '+deferreds.length+' deferreds'); return deferreds; }; function purgeDeletedDocs(){ console.log('purging...'); var purge =...

jQuery ajax requests as Deferred - wrap fail callbacks

jquery,ajax,jquery-deferred,abort
My web-app has all its ajax calls in the form $.post(url, data, successCallback).fail(failCallback) My need is to introduce a mechanism of abort if some circumstances occur. Since calling .abort() also triggers the failCallback, I'm trying to figure out a way (if any), to intercept the abort failure and do not...

Declare jQuery AJAX call for execution later

jquery,ajax,jquery-deferred
I could declare a jQuery AJAX call this way: var foo = $.ajax({ ... }); But that would actually perform the request right then and there, correct? How can I declare the AJAX call without executing it initially, then call it later? Something like: var foo = $.ajax({ ... });...

jquery defered returning data on when

jquery,jquery-deferred
Hi i'm trying to understand $.deffered. How do i return data once say a computation has been completed? function cube(n) { //console.log(n); return n = Math.pow(n, 3); } function compute(n){ var d = $.Deferred(); n = cube(n); //how do i return n upon completed computation? return d.promise(n); } $.when(compute(5)) .done(function(data){...

Deferred then of then is undefined for IndexedDb

javascript,jquery,indexeddb,jquery-deferred,canjs
I'm using CanJs and I'm learning jquery deferred but I have a problem. I created a controller as sort of Singleton to manage data in IndexedDb. First of all, I created an openDb function like this: openDbDeferred: null, openDb: function (dbName, dbVersion) { console.log('Open DB...'); var openDbDeferred = this.openDbDeferred; if...

Using jquery deferred promises inside plugins

jquery,ajax,promise,jquery-deferred
I've written a plugin that is supposed to fetch error messages from an API and display them inside an element's HTML. I want to implement it as a promise, so that other events can be chained to it via a done or always callback. The simplified version of the plugin...

Return response of jquery.deferred object when call the function

javascript,jquery,jquery-deferred
I am trying to create custom dialog box and I return the response of what the user click in that dialog. I use the deferred object but it returns immediately when i call the function. Example fiddle When I call the function var value = showDelete("Hello World"); which always return...