Watch out args in $.ajax success callback vs complete callback – that might reject your Promise!

Watch out, in success callback of $.ajax, you get data as the first argument. This is the more commonly used callback

Whereas in complete, you get jqXHR and textStatus. That makes sense, because no success no data yet

However, a jqXHR is a thenable. If you do

[code] complete: d => resolve(d) [/code]

Your promise chain up one level can get rejected if the ajax req failed. Might not be what you are wishing for

Hours spent on this. Hope this helps anyone trapped in the same hole.

Written on March 19, 2017