jqueryajaxjqxhr

Why does jqXHR.done() return jqXHR object?


Received jqXHR object from my $.post query contains done function. But I realized that this function returns just its jqXHR object:

$.post(query, function(a,b,jqXHR) {
  jqXHR === jqXHR.done() //true
});

How shoud I interpret that?


Solution

  • Since jquery's ajax call return a Promise, any of done(), fail(), always(), and then() functions will return the jqXHR object in order for the Promise to work correctly.

    More information can be found here:
    http://api.jquery.com/jQuery.ajax/#callback-functions