Deferred in jQuery

Async JavaScript

Sample du livre Async Javascript de Trevor Burnham. Présentation complète des objets différés en jQuery.
Télécharger l’extrait du livre (en) : asyncjs-sample

Advantages of promises

At first glance, calling .done() and .fail() doesn’t seem any more useful than the callback syntax we used previously. However, the promise methods offer several advantages. First, the methods can be called multiple times to add more than one handler if desired. Second, if we store the result of the $.ajax() call in a variable, then we can attach the handlers later if that makes our code structure more readable. Third, the handlers will be invoked immediately if the Ajax operation is already complete when they are attached. Finally, we should not discount the readability advantage of using a syntax that is consistent with other parts of the jQuery library.

source :

Laisser un commentaire

six + = 9

NOTE - Vous pouvez utiliser les éléments et attributs HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>