jquery-deferred

jQuery Deferred not working

一笑奈何 提交于 2019-12-18 04:22:08
问题 I am trying out a code as function search(query) { var dfr = $.Deferred(); $.ajax({ url: "http://search.twitter.com/search.json", data: { q: query }, dataType: 'jsonp', success: dfr.resolve }); return dfr.promise(); } Test = { start: function(){ alert("Starting"); } }; function gotresults(data) { alert(data.max_id); } function showDiv() { $('<div />').html("Results received").appendTo('body'); } $.when(search('ashishnjain')) .then(gotresults) .then(showDiv); This works as expected. However

jQuery Deferred not working

自古美人都是妖i 提交于 2019-12-18 04:21:12
问题 I am trying out a code as function search(query) { var dfr = $.Deferred(); $.ajax({ url: "http://search.twitter.com/search.json", data: { q: query }, dataType: 'jsonp', success: dfr.resolve }); return dfr.promise(); } Test = { start: function(){ alert("Starting"); } }; function gotresults(data) { alert(data.max_id); } function showDiv() { $('<div />').html("Results received").appendTo('body'); } $.when(search('ashishnjain')) .then(gotresults) .then(showDiv); This works as expected. However

Promise callback not called in Angular JS

守給你的承諾、 提交于 2019-12-18 03:32:29
问题 If I call connect from doStuff , I get the message that "the socket is connected" , but the callback is not called. What am I missing here? $scope.connect = function() { var defer = $q.defer(); ws = new WebSocket("ws://server.com:port"); ws.onopen = function(){ console.log("Socket connected"); defer.resolve("socket connected"); }; return defer.promise; } $scope.doStuff = function() { $scope.connect().then(function(data) { console.log("And we're off!", data); }); } 回答1: In AngularJS promise

How do I chain a sequence of deferred functions in jQuery 1.8.x?

耗尽温柔 提交于 2019-12-18 03:08:19
问题 Given these functions: function func1() { var dfd = $.Deferred(); setTimeout(function() { dfd.resolve('Password'); }, 1000); return dfd.promise(); } function func2(message) { var dfd = $.Deferred(); setTimeout(function() { if (message == 'Password') { dfd.resolve('Hello World'); } }, 1000); return dfd.promise(); } I'd like to find a better way to do the following. Note this is using jQuery 1.8.x. var promise = func1(); promise.done(function(message1) { var promise2 = func2(message1); promise2

Can I get a jQuery Deferred on document.ready()?

可紊 提交于 2019-12-17 22:50:34
问题 Right after my script is loaded I am making an Ajax request to get some translations. This should always return after the document is ready since I am loading my scripts at the bottom of the page, but I am still curious if it would be possible to get a Deferred Object on the document ready state. That way it would be possible to make sure that both, the document is ready and the Ajax call returned successfully before doing anything else, e.g. like this: $.when( $.ajax('translations'),

pipe() and then() documentation vs reality in jQuery 1.8

本秂侑毒 提交于 2019-12-17 11:22:50
问题 Update: This question is now out of date as the documentation is accurate and up to date. I've been exploring the jQuery Deferred/Promise API for a bit and I'm very confused about the differences between pipe() and then() philosophically and in the jQuery documentation. I've found that pipe() is just an alias for then() as of jQuery 1.8. From jQuery source: // Keep pipe for back-compat promise.pipe = promise.then; Yet the documentation is completely different for pipe() and then() as they

pipe() and then() documentation vs reality in jQuery 1.8

蹲街弑〆低调 提交于 2019-12-17 11:22:46
问题 Update: This question is now out of date as the documentation is accurate and up to date. I've been exploring the jQuery Deferred/Promise API for a bit and I'm very confused about the differences between pipe() and then() philosophically and in the jQuery documentation. I've found that pipe() is just an alias for then() as of jQuery 1.8. From jQuery source: // Keep pipe for back-compat promise.pipe = promise.then; Yet the documentation is completely different for pipe() and then() as they

jQuery jqXHR - cancel chained calls, trigger error chain

拜拜、爱过 提交于 2019-12-17 10:46:36
问题 I am creating a ajax utility for interfacing with my server methods. I would like to leverage jQuery 1.5+ deferred methods from the object returned from the jQuery.ajax() call. The situation is following. The serverside method always returns a JSON object: { success: true|false, data: ... } The client-side utility initiates the ajax call like this var jqxhr = $.ajax({ ... }); And the problem area: jqxhr.success(function(data, textStatus, xhr) { if(!data || !data.success) { ???? // abort

jQuery.when understanding

吃可爱长大的小学妹 提交于 2019-12-17 07:12:19
问题 I am trying to use the jQuery.when to fire two ajax requests and then call some function after the two requests have completed. Here's my code: var count = 0; var dfr; var showData = function(data) { dfr.resolve(); alert(count); // Do something with my data data received }; var method1 = function() { dfr = $.Deferred(); return $.ajax('localhost/MyDataService/DataMethod_ReturnsData', { dataType: "jsonp", jsonp: "$callback", success: showData }); }; var method2 = function() { return $.ajax(

asynchronous keyup events/how to short circuit sequential keyup events for speed boost

℡╲_俬逩灬. 提交于 2019-12-14 02:36:32
问题 On the website I'm building for work, we have a search bar where the user can type in to search various fields stored in data on a set of elements. The problem comes in slower browsers, when they start typing. What I was trying to do is the following, using a jQuery Deferred object: add a key up handler to the input box. when the keyup is triggered, resolve any previously triggered keyups that are still 'pending'. then continue on using the current keyup event. Inside the keyup event itself