pretenderjs / pretender

A mock server library with a nice routing DSL
MIT License
1.26k stars 158 forks source link

jQuery 1.x with passthrough #85

Closed code0100fun closed 8 years ago

code0100fun commented 9 years ago

I can't get passthrough to work with jQuery 1.x. The requests are sent using $.ajax('/path').then(...) but the then callbacks are never fired.

Seems like the onload event is detected on the browser xhr but is not supported by the 1.x jQuery xhr module, so it is not dispatched when the response is received.

I was able to get the events to fire by removing the check for onload and just adding both events.

There is a chance that both events could be fired I'm guessing. Any other concerns I should check into before getting a PR ready?

trek commented 9 years ago

Seems bad. PR would be help.

kottenator commented 9 years ago

I'm using jQuery 1.11.3 too and unfortunately I can't switch to jQuery 2.x :( Could you (Pretender developers), please, check jQuery 1.x support?

olivierlesnicki commented 9 years ago

@trek any update on this one?

olivierlesnicki commented 9 years ago

@code0100fun do you have a PR for this one?

code0100fun commented 9 years ago

I can't think of a clean way to tell when the user has an older version of jQuery without tying Pretender to jQuery in some way.

As a workaround, you may be able to wrap the onload callback of FakeXMLHTTPRequest and call onreadystatechange. That is what jQuery 1.x is using as a success callback.

It looks like onreadystatechange is supposed to be called according to the spec. Maybe FakeXMLHTTPRequest should be calling _readyStateChange here, but I'm not very familiar with the internals.

Any advice @trek or @mike-north ?

olivierlesnicki commented 9 years ago

@code0100fun this is what i've done: https://github.com/pretenderjs/pretender/pull/114

trek commented 8 years ago

addressed by #130