John Smith John Smith - 2 years ago 125
Javascript Question

Deferreds vs $.ajax done/fail

What exactly should I use for standalone asynchronous operations; deferred objects or is ajax

enough? What is the difference?

I understand that
is useful as it allows us to know when all of multiple async operations are completed. But what about one async operation?
allows me to know when it is completed too.

Answer Source

$.ajax() method returns a $.Deferred() object. So you are using deferreds in all cases. You can make your own deferred but ajax will return the same automatically. This is only with jQuery, vanilla javascript have not this functionality.

$.ajax() will return the following promise methods:

fail(), done(), always() and then().

What Jquery forum says:

The jqXHR objects returned by $.ajax() as of jQuery 1.5 implement the Promise interface, giving them all the properties, methods, and behavior of a Promise

Detailed reference to jQuery $.ajax is available here,

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download