jquery-deferred

Backbone Views + deferred handlebars template loading

删除回忆录丶 提交于 2019-12-25 02:43:53
问题 I am trying to load handlebars templates and rendering them via deferred objects / promises, but when i refactored the code by putting in deferreds , errors are occurring: My view is as follows: var indexView = Backbone.View.extend({ initialize: function (options) { this.options = options || {}; manager.getTemplate('path/to/template').then(function(tpl){ // tpl is a handlebar compiled template,returned by getTemplate this.template = tpl; this.render(); // that causes // Uncaught TypeError:

How to make the calling function wait until the called function finishes execution in jquery?

拈花ヽ惹草 提交于 2019-12-25 02:02:20
问题 I have a button which when clicked opens a modal(dashboard_name) in which user enters some value. Based on the value after he clicks submit on that modal I call another function which opens another modal and user enters a different value there and finally when he clicks submit on this modal, I call an api to verify everything is correct. Now, the problem is when I click on the first button to open the modal the execution doesn't wait for the function to get the data from the dashboard_name

Cannot break recursion with $.Deffered() object and $.then()

谁说我不能喝 提交于 2019-12-24 23:16:03
问题 I have to search through word index tables with potentially hundreds of thousands rows. I can restrict my search by passing a list of documents to the search. Request to search for words in many documents return very slowly. So...to improve the UX we're chunking the request into several groups of documents. So, if a user asks to search 90 documents, and the chunk size is 10 documents per query, then we send out 90 / 10 = 9 independent $.ajax() calls. We want the results to come in the order

Catching 403 from $.ajax promise in jQuery v1.x

夙愿已清 提交于 2019-12-24 14:12:43
问题 I'm having problems with catching 403 from $.ajax promise in jQuery v1.x. The same code $.ajax({ dataType: 'jsonp', url: 'http://www.checkupdown.com/accounts/grpb/B1394343/', type: 'GET' }).then(function () { console.log('success', arguments) }, function () { console.log('error', arguments) }); rejects the promise as expected in jQuery v2.x but logs nothing in jQuery v1.x (the promise has readyState == 1 ). The examples use 2.1.3 and 1.11.3 jQuery versions respectively. Why exactly does this

Can I manually resolve a deferred object if a callback might need to reject it?

风格不统一 提交于 2019-12-24 13:56:02
问题 I'm trying to use a custom deferred object to manage some callbacks. I've figured out the easy case: var deferred = $.Deferred(); deferred.done(function() { console.log( 'done' ); }); var json = $.getJSON('/foo'); json.then( function() { deferred.resolveWith(this, arguments); } ); But I need to inspect the response before resolving/rejecting. I'd like to add something like this: deferred.pipe( function(response) { if (response.message === 'error') { return $.Deferred.reject(response); }

after successful ajax retry no .done

与世无争的帅哥 提交于 2019-12-24 10:46:18
问题 I'm making a request to a php file. The response is processed in .done(function(msg){}); and .fail this works fine. But sometimes the request gets an error. I made a retry for this. The retry also works. But if the first time fails and it is successful in de 2 or 3 try my request.done doesn't fire (in firebug I can see that is was successful) My request: var request = $.ajax({ url: "wcf.php", type: "POST", dataType: "xml", async: false, timeout: 5000, tryCount: 0, retryLimit: 3, data: {

jquery deferred in for loop

笑着哭i 提交于 2019-12-24 07:03:46
问题 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 is going on. I have various city names, and I am trying to get central coordinates for each city from the google maps reverse geocoded Here is my function that gets the central coordinates: function getGroupLatLng(groupname){ var deferred =

jQuery Deferred - Adding a callback to the Deferred contract

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 03:01:48
问题 I'm trying to add another asynchronous call to the contract of an existing Deferred before its state is set to success. Rather than try and explain this in English, see the following pseudo-code: $.when( $.ajax({ url: someUrl, data: data, async: true, success: function (data, textStatus, jqXhr) { console.log('Call 1 done.') jqXhr.pipe( $.ajax({ url: someUrl, data: data, async: true, success: function (data, textStatus, jqXhr) { console.log('Call 2 done.'); }, }) ); }, }), $.ajax({ url:

Using jQuery.when with array of deferred objects causes weird happenings with local variables

不羁岁月 提交于 2019-12-23 01:37:36
问题 Let's say I have a site which saves phone numbers via an HTTP call to a service and the service returns the new id of the telephone number entry for binding to the telephone number on the page. The telephones, in this case, are stored in an array called 'telephones' and datacontext.telephones.updateData sends the telephone to the server inside a $.Deferred([service call logic]).promise(); uploadTelephones = function (deffered) { for (var i = 0; i < telephones.length; i++){ deffered.push

How to use jQuery Deferred functionality instead of async.waterfall?

本小妞迷上赌 提交于 2019-12-23 01:18:30
问题 I have a chain of function calls and use async.waterfall. It works like a charm. But I'd like to do it with jQuery Deferred. How to transform my code? The example from jQuery site is like this. Both results are passed to done function: $.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) ).done(function( a1, a2 ) { // a1 and a2 are arguments resolved for the page1 and page2 ajax requests, respectively. // Each argument is an array with the following structure: [ data, statusText, jqXHR ]