2

from what I understand this $.ajax({}).success(function(){...}); is deprecated so I should use done

$.ajax({}).done(function(){...});

however, this

   $.ajax({
        success: function(){...}
    });

is not deprecated, right? what is its functionality difference from that:

$.ajax({}).done(function(){...});

can they be used interchangebly any time or are they different.

Is success only called when function succeeds while done is called all the time?

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
  • The .done() method replaces the deprecated .success() method. See this... http://api.jquery.com/jquery.ajax/ – Rakesh_Kumar Jan 12 '15 at 05:49
  • 2
    There is in most cases no real difference in how you'd use them, but `done` uses deferreds and promises while `success` is just a callback. Stick with using `done` from now on, as `success` will probably be removed some time in the future. – adeneo Jan 12 '15 at 05:52
  • @Rakesh_Kumar I know that. that is not my question the .done does not replace the parameter success (not the .success) – Saher Ahwal Jan 12 '15 at 06:06
  • @FelixKling but then what defines succeeds? a 200 response from server/ – Saher Ahwal Jan 12 '15 at 06:10
  • 1
    I guess any of the 2xx status codes. Probably the 3xx as well. – Felix Kling Jan 12 '15 at 06:12
  • I think it may be possible that your ajax call will get done but not successful.Lets say you want content type json while server is returning xml in that case ajax call is not but neither error not success. – Innovation Jan 12 '15 at 06:18
  • `success:` as a parameter of ajax is original implementation to deal with successful response. `.success()` is a method of `deferred` object, since `$.ajax` will return a deferred object. and it does have same effect as `success:` in ajax as a parameter. see similar question [link](http://stackoverflow.com/a/8840315/3462558) – Qiang Feb 09 '16 at 22:25

0 Answers0