Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes to $.ajaxJSONP #660

Closed
wants to merge 1 commit into from
Closed

fixes to $.ajaxJSONP #660

wants to merge 1 commit into from

Conversation

zertosh
Copy link
Contributor

@zertosh zertosh commented Dec 13, 2012

When making JSONP requests:

  1. settings.beforeSend wasn't being called.
  2. The ajaxBeforeSend and ajaxError events weren't being fired.
  3. There was inconsistent behavior with timeouts between $.ajax and $.ajaxJSONP. In $.ajax when there is a timeout, ajaxError is called and that subsequentely calls ajaxComplete. In $.ajaxJSONP, a timeout skips ajaxError and calls ajaxComplete twice. First with a status of abort and then again with a status of timeout.
  4. When the request is aborted either by (1) calling xhr.abort() or (2) because of a timeout, or (3) the request raises an onerror event, the global window[callbackName] is set to function empty () {} instead of deleting it. So the global scope stays polluted and empty() retains a reference to <script> which then can't be garbage collected.
  5. When a request is aborted before completion/timeout by calling xhr.abort() and there is a timeout set, the timeout would not to be cleared.
  6. If you didn't specify an error callback in the options of $.ajaxJSONP and there is an error then there is no cleaning up of <script> or window[callbackName], the error event isn't fired, and $.active isn't updated. (Kinda related to 4).

I only wrote tests for (1) and (6). Any help?

mislav added a commit that referenced this pull request Dec 24, 2012
Introduces several failing cases pointed out in #660
@mislav
Copy link
Collaborator

mislav commented Dec 24, 2012

Hey @zertosh

Thanks! I have merged your fixes (and made an additional fix) in 4769efd...eb6065c

I haven't used your tests because beforehand I've written much more robust callback, abort, and timeout tests and ensured there are failing cases for each of your reported issues above, then applied your patch which fixed all but one of them. (I've changed manual abort() to call ajaxError instead of ajaxComplete.)

Behavior described under (4) is by design. If the request is manually aborted or there is a timeout, we want the callback to be an empty function instead of unset because SCRIPT will finish eventually and will try to call the callback. However, empty doesn't contain a reference to SCRIPT, so it's not a big deal. Yes, the global namespace gets polluted a bit.

@mislav mislav closed this Dec 24, 2012
lopper pushed a commit to buddydvd/zepto that referenced this pull request Apr 24, 2013
Introduces several failing cases pointed out in madrobby#660
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants