1

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?

Karol Selak
  • 4,248
  • 6
  • 35
  • 65
  • 1
    The `jqXHR` object is a superset of the native XMLHttpRequest object. In jQuery it is a deferred object, that also has the jQuery methods that deferreded objects have. One of those methods is `done()`, and as `done ()` also *returns* the deferred object, you're comparing the exact same object, and comparing an object to itself, returns `true` – adeneo Sep 09 '17 at 21:44
  • So, in that situation, why XMLHttpRequest returns itself with done()? Should I interpret it just as 'true' value? – Karol Selak Sep 09 '17 at 21:54

1 Answers1

3

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

Dekel
  • 60,707
  • 10
  • 101
  • 129