Search code examples
javascriptjqueryjquery-callback

Benefit to using jquery's .done()


Possible Duplicate:
jQuery.ajax handling continue responses: “success:” vs “.done”?

Is there any benefit to using jquery's done method compared to the success callback ? As far as I can tell these would both execute similar (if not the same?)

Case 1 using $.get callback

$.get("....", function(data){
        console.log(data);
});

Case 2 using .done()

$.get("....").done(function(data){
     console.log(data);
});

Solution

  • You can attach any number of handler before or after it's processed and count on them all firing. You don't have to squeeze everything into a single function.

    var request = $.get("....")
    request.done(function(data) {
        console.log(data);
    });
    request.done(function(data) {
        // do something else
    });
    request.done(someOtherPredefinedFunction);
    

    Besides, I believe the success handler is deprecated and scheduled for eventual removal.