0

What is the difference between the 2?

Why this confuses me is due to the documentation. Referring to the one the documentation call 'jqXHR' https://api.jquery.com/jQuery.getJSON/#jqxhr-object

We see this:

The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callback methods are removed as of jQuery 3.0. You can use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

So basically, success(), error() et all is deprecrated, so use done(), fail() et al.

So, in something like this example from the very page,

  dataType: "json",
  url: url,
  data: data,
  success: success
});

Is it better to handle success as such or as .success() / .done() ?

How would the above differ from this?

$.ajax({
  dataType: "json",
  url: url,
  data: data,
})
.done(function(data){ 
    success 
});
Erik
  • 219
  • 3
  • 16
  • Sorry for closing your question, it's already been answered in so much details - we could not rewrite it all again in a better way. – Roko C. Buljan Apr 27 '21 at 02:44
  • Tl;Dr; use the *"newer"* `.done() .fail()` etc. If you really want a first glimpse at those methods., all it takes is to open the unminified jQuery source code. – Roko C. Buljan Apr 27 '21 at 02:48
  • What's not included (at quick glance) in the duplicate and what the doc is saying is that there *used to be* `$.ajax({...}).success(...` - this has been removed and replaced with `$.ajax({...}).done(..` - there is **another option** which is `$.ajax({ .., success: function() { .. } })` - the `success:` option to settings - this has *not* been removed. `success:` and `.done()` are essentially equivalent but one is a callback and the other a deferred method. – freedomn-m Apr 27 '21 at 06:54

0 Answers0