Return already resolved promise

@Eselk, In my experience, the $.Deferred(function(def) {…}); construction is rarely needed, though I guess it can be quite useful in some circumstances. Firstly, : return $.Deferred(function(def) { def.resolve(); }).promise(); will simplify to : return $.Deferred().resolve().promise(); Secondly, in DataService.makeRequest() you can avoid the need for an explicit $.Deferred by exploiting .then(), as follows : function DataService() … Read more

Asynchronous JavaScript – Callbacks vs Deferred/Promise [duplicate]

Promises also rely on callbacks behind the scene, so it’s not really one vs. the other. The benefit of callbacks is that they are easy to implement with plain JavaScript (for example in ajax calls). Promises require an additional abstraction layer, which usually means that you’ll rely on a library (not an issue in your … Read more

jQuery.when understanding

function showData(data1, data2) { alert(data1[0].max_id); alert(data2[0].max_id); } function method1() { return $.ajax(“http://search.twitter.com/search.json”, { data: { q: ‘ashishnjain’ }, dataType: ‘jsonp’ }); } function method2() { return $.ajax(“http://search.twitter.com/search.json”, { data: { q: ‘ashishnjain’ }, dataType: ‘jsonp’ }); } $.when(method1(), method2()).then(showData);​ Here’s a working jsFiddle

Deferred versus promise

First: You cannot use $.Promise(); because it does not exist. A deferred object is an object that can create a promise and change its state to resolved or rejected. Deferreds are typically used if you write your own function and want to provide a promise to the calling code. You are the producer of the … Read more

Reactjs async rendering of components

There are two ways to handle this, and which you choose depends on which component should own the data and the loading state. Move the Ajax request into the parent and conditionally render the component: var Parent = React.createClass({ getInitialState: function() { return { data: null }; }, componentDidMount: function() { $.get(‘http://foobar.io/api/v1/listings/categories/’).done(function(data) { this.setState({data: data}); … Read more

When should I use jQuery deferred’s “then” method and when should I use the “pipe” method?

Since jQuery 1.8 .then behaves the same as .pipe: Deprecation Notice: As of jQuery 1.8, the deferred.pipe() method is deprecated. The deferred.then() method, which replaces it, should be used instead. and As of jQuery 1.8, the deferred.then() method returns a new promise that can filter the status and values of a deferred through a function, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)