jquery-deferred

Async TypeScript function return jQuery promise

五迷三道 提交于 2020-01-05 12:15:31
问题 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

Does jQuery.Deferred have a bug when a jQuery.Deferred object is passed to deferred.resolve?

走远了吗. 提交于 2020-01-05 03:41:28
问题 Given the code using Promise constructor let promise = () => new Promise(resolve => resolve(1)); new Promise((resolve, reject) => { setTimeout(() => reject("10 seconds exceeded"), 10000); resolve(promise()) }) .then(data => console.log(data)) .catch(err => console.error(err)); 1 is logged at console Given the equivalent code using jQuery.Deferred the jQuery.deferred object is logged at .then() , not the value passed to jQuery.deferred.resolve let promise = () => new $.Deferred(dfd => dfd

When to Use deferred.reject()?

烂漫一生 提交于 2020-01-04 06:20:49
问题 I’m very confused about when to use deferred.resolve() and deferred.reject() . Quick Example var doSomething = function() { var deferred = $.Deferred(); if ( typeof myVar === "object" ) { // Do something with myVar - Start. deferred.resolve(); // Do something with myVar - End. } else { // myVar isn't an object, but the function has finished executing // and that's what I want to know. // With reject() I'll be forced to use always() instead of done() // because there'll be also a fail() method

jQuery - Deferreds waiting for an array of ajax requests to complete even failures

心已入冬 提交于 2020-01-03 15:58:03
问题 How can execute a function after a number of ajax requests have all completed regardless of whether they succeeded or error-ed out? I've been trying to use $.when.apply(this, array) to pass an array of deferred jqXHR objects. However just like the docs say In the multiple-Deferreds case where one of the Deferreds is rejected, jQuery.when immediately >fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be >unresolved at that point. How can leverage jQuery

jQuery - Deferreds waiting for an array of ajax requests to complete even failures

回眸只為那壹抹淺笑 提交于 2020-01-03 15:56:09
问题 How can execute a function after a number of ajax requests have all completed regardless of whether they succeeded or error-ed out? I've been trying to use $.when.apply(this, array) to pass an array of deferred jqXHR objects. However just like the docs say In the multiple-Deferreds case where one of the Deferreds is rejected, jQuery.when immediately >fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be >unresolved at that point. How can leverage jQuery

how to use jquery deferred with vktemplate / queuing ajax requests

五迷三道 提交于 2020-01-03 05:18:14
问题 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 promise doesn't get resolved until after these two things happen? $(document).on('click', '.ajax', function() { $.when(ajax1('<p>first</p>'), ajax2('<p>second</p>'), ajax3('<p>third</p>')) .then(function(results1, results2, results3) { console.log

Backbone, trigger an events when all is loaded

别等时光非礼了梦想. 提交于 2020-01-01 17:11:40
问题 In my backbone app I load 3 Collections and I bind the "reset" event at the render function. So, in this way, when I fetch the Collections, I print the various results, but not simultaneously. I would use the jquery deferred methods ($.when, $.then) to print all simultaneously, how to do this if I use the "bind events" on the views? this is the code: Router: App.Routers.test1 = Backbone.Router.extend({ routes: { "/test" : "test" }, initialize: function() { // Models this.Models_1 = new App

How do you use .when().then() to trigger a function when using deffered objects in the .when()?

自作多情 提交于 2020-01-01 12:31:22
问题 I have a page in which I have a variable number of AJAX calls to make which are triggered on a common event. The AJAX calls themselves are to update related fields in a SQL database. Once all the calls are complete, I want to refresh the page so that it now reflects the changes just made. I used the following question/answer on here to get so far.. jQuery when each is completed, trigger function Here is my code so far: var team_update = function(e) { var $items = $('.sortable-items'); var

jQuery.Deferred exception: The string did not match the expected pattern

被刻印的时光 ゝ 提交于 2020-01-01 06:44:07
问题 I've a little headache with this console error, ONLY on Safari (working on MacBook actually). I have this function: function exists(element){ var exists = document.querySelector(element); return exists; } invoked inside another function: function includeHoverStylesheet(){ var path = $("body").attr("data-hover"); if (!("ontouchstart" in document.documentElement || exists("link[href='" + path + "'"))) { var link = document.createElement("link"); link.rel = "stylesheet", link.href = path,

How can I tell if an object is a jQuery Promise/Deferred?

心已入冬 提交于 2019-12-31 17:49:10
问题 I have a function that takes a single argument. I need to be able to tell if this argument is a jQuery Promise or Deferred object. If not, then the value may be of any type and have any properties, so it's not safe to just just for the presence of the promise methods. Here's an example of how I'd like my function to behave: function displayMessage(message) { if (message is a Promise or Deferred) { message.then(displayMessage); } else { alert(message); } } Notice the recursive handling of