kriskowal / q

A promise library for JavaScript
MIT License
14.93k stars 1.2k forks source link

Using jQuery v3+, Q($.ajax) promise returned doesn't seem to resolve #834

Closed ericnewton76 closed 6 years ago

ericnewton76 commented 6 years ago

https://stage-cremationbasics.cp-access.com/ un:arbormemorialreview pw:Arb0rMem0rial!

Expected behavior: breakpoint on 8154 is hit after Q($.ajax({})) resolves. Note that if you actually hit 8154, the following lines will probably fail, I've never been able to get to that point. jquery ajax is resolving its promise as valid, but its not coming back through then().

Actual behavior: then() never resolves with valid data.

If you run things through Fiddler, the service call to WCOService.asmx/ShopifyCall is return 200 OK, but somewhere between jquery ajax and Q, its resolving as rejected. Of note, Jquery Ajax documentation notates that the promise behavior changes in v3 compared to prior...

on http://api.jquery.com/jquery.ajax/ search for "deprecation notice", although i'm not sure this is the real issue.

ericnewton76 commented 6 years ago

I think I just stumbled onto what the problem is.

XmlHttpRequest, in all its (idiotic) wisdom, will silently follow a Location header and jquery ajax bubbles that out as a rejection. However, this is standard practice for REST apis on POST to respond with 201 Created and a Location header of where to go to retrieve the newly POST'd data.

Therefore the jquery ajax is detecting the XmlHTtpRequest redirect, and for some reason beyond logic, raises its own reject which bubbles out to Q's reject. Here's the crazy part... the old success callback is called before calling the reject on the returned jquery promise!

Aye vay.

ericnewton76 commented 6 years ago

Actually it was stupid ASMX WebMethod plopping {"d":null} at the end of a long response grrrrrrrrrrrrrrrrrrrrrrrr