jquery-deferred

jQuery deferred ajax cache

左心房为你撑大大i 提交于 2019-12-31 05:39:09
问题 I read the top answer to this question regarding the use of jQuery Deferred. I'm looping through an array of IDs. For each ID, I need to get data pertaining to it either from an ajax request, or from a cache if an ajax request had already successfully returned the data before. During each loop, I use a $.when() to observe whether getData() returns something from cache or a successful ajax call, before processing that ID. The current problem is that the ID processing proceeds anyways without

Notify after async task is done

岁酱吖の 提交于 2019-12-31 05:17:30
问题 I'm building a game with move.js for animation, but it takes too long so when the player click on the right solution it displays the winning message before the right solution change it's color, so I used deferred object to fire an event and catch it when the animation ends. Here's my code: var deferred = new $.Deferred(); click(e); //show message when game is over $.when(deferred).then(function(){ if (this.checkIfWin()){ alert('you won !'); this.nextLevel(); } }); function click(e){ move(e)

syntax for Jquery.deferred , making synchronous function return promise

…衆ロ難τιáo~ 提交于 2019-12-31 03:23:27
问题 A quick question on how to use Jquery.deferred to make a slow synchronous function return a promise instead. What I've done so far is this : function sayIt(ms) { setTimeout( function() { console.log('what I say'); }, ms); } function doIt() { return $.Deferred( function() { sayIt(2000); }).promise(); } doIt().then( function() { console.log('ah'); }); the sayIt(2000) always goes through but the chained function after the 'then' never fires. If I do this : doIt().then( console.log('ah')); the

Chain of Jquery Promises

ぐ巨炮叔叔 提交于 2019-12-30 03:59:10
问题 I have a simple chain of events: Get Columns from a metaData table (async) load selected columns (async) render list I used to just the chain these functions, each calling the next when it had completed. However, its not very obvious what's going (calling getColumnsFromMeta results in the view being populated). So in the interest of clarity and code re-use I'd like to refactor these using JQuery Promises . I have used promises before. But how do I chain more than two? getColumnsFromMeta ()

JQuery deferred with .each()

耗尽温柔 提交于 2019-12-30 00:39:09
问题 Any ideas how you might use JQuery's deferred methods with a function that detects all changed forms and submits each one as an Ajax post? I can get the same thing working if I just list a load of form submissions but if I use... $('form.changed').each(function(){ return $(this).submitWithAjax(); }); A fuller version of the code that I'm trying to get working is here... at JS Fiddle Thanks in advance! 回答1: Instead of ".each()", use ".map()": var deferreds = $('form.changed').map(function(i,

How to use jQuery Deferred with custom events?

别来无恙 提交于 2019-12-29 14:15:14
问题 I have two abstracted processes (e.g. managed within js objects using the revealing module pattern that do not expose their internals) that fire custom events when they complete. I want to perform an action when both custom events have fired. The new Deferred logic in jQuery 1.5 seems like it would be an ideal way to manage this, except that the when() method takes Deferred objects that return a promise() (or normal js objects, but then when() completes immediately instead of waiting, which

Is any jQuery version compliant to Promise/A specifications?

♀尐吖头ヾ 提交于 2019-12-28 16:56:09
问题 After going through several articles I have come to know that promise implementation is there in jQuery. But I am not sure whether any version of jQuery is Promise/A compliant or not. 回答1: Update 2015: jQuery 3.0 is Promises/A+ compatible. See this issue on GitHub so 3.0 beta is 3.0 compatible and when 3.0 is out it will also be compatible. Until then - the below still applies. All jQuery versions (up to 3.0) feature a broken promise implementation They don't allow error handling well, and

jQuery .when troubleshooting with variable number of arguments

那年仲夏 提交于 2019-12-28 08:36:21
问题 I'm having an issue with using jQuery.when() to wait for multiple ajax requests to finish before calling another function. Each ajax request will get JSON data, and looks something like this: function loadData(arg){ var ajaxCall = $.ajax( URL // depends on arg ) .error( .... ); return ajaxCall; } When the request is called, the return value (ajaxCall) is added to a list called ajaxRequests. ajaxRequests = []; ajaxREquests.push(loadData(arg)) When all the requests have been made, I'm trying to

Wait until multiple functions, which may or may not call ajax internally, are complete in jQuery?

岁酱吖の 提交于 2019-12-25 07:01:24
问题 I am currently validating a few inputs clientside. When the user submits the form, I want to check the values for the form inputs, and then do something once all the checks are complete $('form').submit(function() { var input1 = $('form #input1'); var input2 = $('form #input2'); //validate both input values validate_input(input1); validate_input(input2); //wait until all validation complete to execute code here return false; }); Here, the "validate_input" function will check the input value.

$.when() with array of Deferreds not calling done action

可紊 提交于 2019-12-25 04:14:38
问题 I am trying to use a variable set of deferred functions in an array along with $.when() . These functions fetch data from the server and render it in the DOM. After all these are done, some scripts are loaded and a couple post-load actions are performed. Here is what I am using: function loadAllGames(updateGames, updatePlayoffs) { var deferredLoads = []; if (updateGames !== false) deferredLoads.push($.Deferred(loadGames)); if (updatePlayoffs !== false) deferredLoads.push($.Deferred