jquery-deferred

Modifying JSONP results before success callback

▼魔方 西西 提交于 2019-12-10 22:56:43
问题 I'd like to load some JSON data from an external service. However, it provides { foo: ..., bar: ..., useful: {...} } and what I really care about is in the "useful" part. I need to pass just that part to the success callback. I'm trying to use Deferred to load from multiple data sources at once -- something like this. I'd like to retrieve the data, "massage" the result, and have just the "useful" part in the example above actually passed to the then callback. My understanding is that when you

Stoping jquery .then chain via user input

走远了吗. 提交于 2019-12-10 22:50:06
问题 This is probably a simple question, but i'm totally lost. I have this function. m.util.genericSwipeVertFunc = function ( ajaxRequest, swipeOutTarget, swipeInTarget ) { var stage1, stage2, failStage, dfd = $.Deferred(), finalStage, functionPromise; // Swipe of screen wait for ajax request stage1 = function () { return $.when( ajaxRequest, // Returns $.Deferred() m.util.animateDeffered(swipeOutTarget, "fadeOutDown", true) // Returns $.Deferred() ); }; // Swipe and Show stage2 = function () {

Using Sinon.js and preventing a call to my app server

柔情痞子 提交于 2019-12-10 17:04:58
问题 Simple enough question: I want us sinon.js to test a piece of javascript to ensure that it calls the $.ajax method while doing two things: I don't want to actually hit the server I want to mock up a response from the server so here's the JS: $.ajax url: "/tickets/id.json" dataType: 'json' .done (data) => HandlebarsTemplates["tickets/popup_title"] data and here's my test: describe 'PopupDisplayer', -> beforeEach -> loadFixtures 'popup_displayer' new PopupDisplayer @title_stub = sinon.stub(

Propagating events between JQuery.Deferred objects

六眼飞鱼酱① 提交于 2019-12-10 16:46:45
问题 How can I propagate all events on one JQuery.Deferred() object to another ? Is there a better / simpler / shorter way then handling both .fail and .then .done by calling the other objects .rejectWith and .resolveWith ? I am assuming that I don't have to handle .done .then as it will be called when I call Reject or resolve. I suspect that maybe this can be done using .pipe but I am not sure how. UPDATE: Note: I also I fixed some of the text above per @Frédéric Hamidi's comment. What I am

delay for jquery promises

怎甘沉沦 提交于 2019-12-10 14:40:10
问题 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 the way how I use it: run: function () { return $() .promise() .then(function () { console.log("call together"); console.log("call together"); }) .then(delay(2000))

Implementing a fallback using promises

匆匆过客 提交于 2019-12-10 13:34:59
问题 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 to 'callback hell': var data; getData1(function() { getData2(function () { getData3(function () { alert('not found'); }) }) }); where the implementations may look something like: function getData1(callback) { $

jquery-ajax multiple calls

孤人 提交于 2019-12-10 11:27:51
问题 I'm using the following code to have multiple ajax requests like this: request 1 start | request 1 finish | request 2 start | request 2 finish | ... This is the code: var startingpoint = fireRequest(1); $.each(types,function(ix,type) { startingpoint = startingpoint.pipe( function() { alert(startingpoint.status); // undefined return fireRequest(type); }); }); fireRequest is just a switchcase to the correct ajax function which returns $.ajax(...) I'd like the chain to stop when one request

Javascript Promise vs jQuery Deferred [closed]

限于喜欢 提交于 2019-12-10 02:29:18
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . What are the pros & cons of Javascript Promises vs jQuery Deferred Objects? For example, what issues do they each have, if any? A fellow stack overflow member stated: "...real promises are real, and fake promises are fake." What did he mean by this? 回答1: There is no such

not asynchronous function executed as jQuery Deferred

孤街醉人 提交于 2019-12-09 14:55:11
问题 Lets say I want to process some tasks in the synchronous manner, so I have this function: function executePromiseQueueSync(queue){ var seed = $.Deferred(), finalPromise; finalPromise = _.reduce(queue, function(memo, promise){ return memo.then(function(){ return promise.funct.apply(null, promise.argmnt); }); }, seed.promise()); seed.resolve(); return finalPromise; } Now I can use it to process some files: _.each(fileList, function(element, index, list){ _.each(element, function(el, idx, lst){

Deferred and Ajax

不羁岁月 提交于 2019-12-09 05:44:58
问题 Reading a JSON-Service like this: $.ajax({ url:'activeIDs', success : function(data){ // data = [14,15] var tableRows = []; for (var dataIndex=0; dataIndex < data.length; dataIndex++) { var isLast = dataIndex == (data.length - 1); $.ajax({ url: 'info?id=' + data[dataIndex], success: function(data2) { // "foo", "bar" tableRows.push(data2.name); if (isLast) { alert(tableRows.length); } } }); } } }); First network-trace is: activeIDs = [14,15] info?id=14 (takes 2 seconds) = "foo" info?id=15