deferred

Defer attribute doesn't work with Google Maps API?

丶灬走出姿态 提交于 2019-12-18 05:02:36
问题 I'm trying to make sure the Google map is the last thing that loads on the page and doesn't affect the performance of the page negatively. When the defer attribute is placed after ...sensor=false", the map does not appear. What's the best way to use the defer attribute with Google maps? Is this even possible? <div id="map-canvas"></div> <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false" defer></script> <script defer> function

jQuery Deferred - getting result of chained ajax calls

蹲街弑〆低调 提交于 2019-12-17 16:26:34
问题 following problem - I have to call ajax function number of times, and when all functions are complete, get all results into array. I came up with this: function doAjax(xx){ var xdata = {json: $.toJSON({name: xx}), delay: 1}; return $.ajax({ url:"/echo/json/", data:xdata, type:"POST" }); } var carr = [doAjax('a'),doAjax('b'),doAjax('c'),doAjax('d')] var result = []; $.when( carr ) .done(function(data){ console.log(data); $.each(data, function(ix,val){ console.log(val.name); }); }); Fiddle here

What's the difference between a Deferred object and its own promise object?

拈花ヽ惹草 提交于 2019-12-17 15:35:39
问题 Let's create a simple Deferred object: defer = $.Deferred( function ( defer ) { setTimeout( defer.resolve, 3000 ); }); The above Deferred object will be in the "pending" state for 3 seconds, and then switch to the "resolved" state (at which point all the callbacks bound to it will be invoked). Let's also retrieve the promise of that Deferred object: promise = defer.promise(); Now, to add callbacks which are going to be invoked once the Deferred object is resolved, we can use .done() or .then(

Chain ajax and execute it in sequence. Jquery Deferred

大憨熊 提交于 2019-12-17 08:59:38
问题 I have 3 processes that needs ajax to complete. But it is asynchronous and it fails to do what I wanted to do.. Lets say: function a(param1, param2) { $.post(..., function(result){ if(result){ b(); } else { console.log("failed a"); } }) } function b() { $.post(..., function(result){ if(result){ c(); } else { console.log("failed b"); } }) } function c() { $.post(..., function(result){ if(result){ console.log("successful"); } else { console.log("failed b"); } }) } I want it to execute like this

javascript promise not passing all arguments (using Q)

天大地大妈咪最大 提交于 2019-12-17 06:51:57
问题 I am having trouble passing all arguments. My promise callback only receives one instead of three: var asyncFunction= function(resolve) { setTimeout(function() { resolve("Some string that is passed", "and another", "third"); }, 1000); }; var promiseFunction = function () { var deferred = Q.defer(); asyncFunction(deferred.resolve); return deferred.promise; }; promiseFunction().then(function() { // Only one argument is passed here instead of 3 // { '0': 'Some string that is passed' } console

AngularJS : Where to use promises?

删除回忆录丶 提交于 2019-12-17 02:24:52
问题 I saw some examples of Facebook Login services that were using promises to access FB Graph API. Example #1 : this.api = function(item) { var deferred = $q.defer(); if (item) { facebook.FB.api('/' + item, function (result) { $rootScope.$apply(function () { if (angular.isUndefined(result.error)) { deferred.resolve(result); } else { deferred.reject(result.error); } }); }); } return deferred.promise; } And services that used "$scope.$digest() // Manual scope evaluation" when got the response

Recursive Ajax deferred object

若如初见. 提交于 2019-12-13 12:50:36
问题 I need to paste some data in the DOM when a recursive ajax function ends its recursion. The problem I have is that "$.when().done()" will trigger in the first step of rescursion but I need that it triggers on the last step of recursion, when recursion ends. I really have no idea how to achive it, any help will be kindly apreciated! function recursiveFunction(data) { // do something with data // and remove elements processed from data var param = { "data" : data }; return $.ajax({ data: param,

Should I return the result of deferred.resolve/reject?

我是研究僧i 提交于 2019-12-13 06:02:13
问题 When working with Q deferreds, should I return the result of deferred.resolve and deferred.reject ? function foo() { var deferred = Q.defer(); service.doSomethingAsync({ success: function() { deferred.resolve(); // should I return the result of resolve here? }, fail: function(err) { deferred.reject(err); // should I return the result of reject here? } }); return deferred.promise; } 回答1: Your code can be changed to: function foo() { var deferred = Q.defer(); service.doSomethingAsync({ success:

Unsure of how to implement $.defered

可紊 提交于 2019-12-13 06:01:54
问题 This should be simple: I have a 5-second animation, after which I want to .append('Done'). I want to make use of deferrals. I made the function deferred, added a resolve statement (with no argument, so I'm not sure that's needed), and have it returning a promise. But I cannot get the .append to wait for my fader() to execute. $(document).ready(function () { var fader = function () { var dfr = new $.Deferred(); $('#container').fadeOut(2500).fadeIn(2500); dfr.resolve(); return dfr.promise(); };

Why does my jQuery when().then() function trigger before the ajax request in when is done?

时光怂恿深爱的人放手 提交于 2019-12-13 02:37:15
问题 I need to set an async callback, because a function fetches content from a remote location. I'm doing this: $.when( priv[box.view.renderWith](content, box.view.gadget_id) ).then(function(late) { console.log("done"); console.log(late) console.log($(content)) $(content).append(late).enhanceWithin(); }); with my when function triggering a single Ajax request. In it's callback I'm returning an element to append to $(content) . My problem is, the then function fires immediately and long before my