Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix($httpBackend): don't error when JSONP callback called with no parameter #6735

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Mar 18, 2014

This change brings Angular's JSONP behaviour closer in line with jQuery's. It
will no longer treat a callback called with no data as an error, and will no
longer support IE8 via the onreadystatechanged event.

BREAKING CHANGE:

Previously, the JSONP backend code would support IE8 by relying on the
readystatechanged events. This is no longer the case, as these events do not
provide adequate useful information for deeming whether or not a response is
an error.

Previously, a JSONP response which did not pass data into the callback would
be given a status of -2, and treated as an error. Now, this situation will
instead be given a status of 200, despite the lack of data. This is useful for
interaction with certain APIs.

Previously, the onload and onerror callbacks were added to the JSONP script
tag. These have been replaced with jQuery events, in order to gain access to
the event object. This means that it is now difficult to test if the callbacks
are registered or not. This is possible with jQuery, using the
$.data("events") method, however it is currently impossible with jqLite. This
is not expected to break applications.

Closes #4987

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#6735)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!


}

it('should call callback with status -2 when script fails to load', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is no longer correct, we don't want to give a status of -2 when the callback is called with no data.

@caitp caitp added this to the 1.3.0-beta.3 milestone Mar 18, 2014
@IgorMinar
Copy link
Contributor

lgtm

…ameter

This change brings Angular's JSONP behaviour closer in line with jQuery's. It will no longer treat
a callback called with no data as an error, and will no longer support IE8 via the onreadystatechanged
event.

BREAKING CHANGE:

Previously, the JSONP backend code would support IE8 by relying on the readystatechanged events. This
is no longer the case, as these events do not provide adequate useful information for deeming whether
or not a response is an error.

Previously, a JSONP response which did not pass data into the callback would be given a status of -2,
and treated as an error. Now, this situation will instead be given a status of 200, despite the lack
of data. This is useful for interaction with certain APIs.

Previously, the onload and onerror callbacks were added to the JSONP script tag. These have been
replaced with jQuery events, in order to gain access to the event object. This means that it is now
difficult to test if the callbacks are registered or not. This is possible with jQuery, using the
$.data("events") method, however it is currently impossible with jqLite. This is not expected to
break applications.

Closes angular#4987
@caitp
Copy link
Contributor Author

caitp commented Mar 19, 2014

@IgorMinar unfortunately I had to hack this a bit to get E2E tests working, oddly enough the implementation that you said looked good wasn't actually making any requests (or at least, the callbacks were never being called). It seems to work now, though. weird.

The updated implementation is a bit uglier, but I think that stuff can be fixed up later

@caitp caitp closed this in 6680b7b Mar 19, 2014
@caitp
Copy link
Contributor Author

caitp commented Mar 19, 2014

I do hope this doesn't need to be reverted, at least tests are passing and a simple test on plnkr worked :u

caitp added a commit that referenced this pull request Mar 21, 2014
…ameter

This change brings Angular's JSONP behaviour closer in line with jQuery's. It will no longer treat
a callback called with no data as an error, and will no longer support IE8 via the onreadystatechanged
event.

BREAKING CHANGE:

Previously, the JSONP backend code would support IE8 by relying on the readystatechanged events. This
is no longer the case, as these events do not provide adequate useful information for deeming whether
or not a response is an error.

Previously, a JSONP response which did not pass data into the callback would be given a status of -2,
and treated as an error. Now, this situation will instead be given a status of 200, despite the lack
of data. This is useful for interaction with certain APIs.

Previously, the onload and onerror callbacks were added to the JSONP script tag. These have been
replaced with jQuery events, in order to gain access to the event object. This means that it is now
difficult to test if the callbacks are registered or not. This is possible with jQuery, using the
$.data("events") method, however it is currently impossible with jqLite. This is not expected to
break applications.

Closes #4987
Closes #6735
caitp added a commit to caitp/angular.js that referenced this pull request Apr 7, 2014
…ameter

This change brings Angular's JSONP behaviour closer in line with jQuery's. It will no longer treat
a callback called with no data as an error, and will no longer support IE8 via the onreadystatechanged
event.

BREAKING CHANGE:

Previously, the JSONP backend code would support IE8 by relying on the readystatechanged events. This
is no longer the case, as these events do not provide adequate useful information for deeming whether
or not a response is an error.

Previously, a JSONP response which did not pass data into the callback would be given a status of -2,
and treated as an error. Now, this situation will instead be given a status of 200, despite the lack
of data. This is useful for interaction with certain APIs.

Previously, the onload and onerror callbacks were added to the JSONP script tag. These have been
replaced with jQuery events, in order to gain access to the event object. This means that it is now
difficult to test if the callbacks are registered or not. This is possible with jQuery, using the
$.data("events") method, however it is currently impossible with jqLite. This is not expected to
break applications.

Closes angular#4987
Closes angular#6735
caitp added a commit to caitp/angular.js that referenced this pull request Apr 7, 2014
…ameter

This change brings Angular's JSONP behaviour closer in line with jQuery's. It will no longer treat
a callback called with no data as an error, and will no longer support IE8 via the onreadystatechanged
event.

BREAKING CHANGE:

Previously, the JSONP backend code would support IE8 by relying on the readystatechanged events. This
is no longer the case, as these events do not provide adequate useful information for deeming whether
or not a response is an error.

Previously, a JSONP response which did not pass data into the callback would be given a status of -2,
and treated as an error. Now, this situation will instead be given a status of 200, despite the lack
of data. This is useful for interaction with certain APIs.

Previously, the onload and onerror callbacks were added to the JSONP script tag. These have been
replaced with jQuery events, in order to gain access to the event object. This means that it is now
difficult to test if the callbacks are registered or not. This is possible with jQuery, using the
$.data("events") method, however it is currently impossible with jqLite. This is not expected to
break applications.

Closes angular#4987
Closes angular#6735
caitp added a commit to caitp/angular.js that referenced this pull request Apr 8, 2014
…ameter

This change brings Angular's JSONP behaviour closer in line with jQuery's. It will no longer treat
a callback called with no data as an error, and will no longer support IE8 via the onreadystatechanged
event.

BREAKING CHANGE:

Previously, the JSONP backend code would support IE8 by relying on the readystatechanged events. This
is no longer the case, as these events do not provide adequate useful information for deeming whether
or not a response is an error.

Previously, a JSONP response which did not pass data into the callback would be given a status of -2,
and treated as an error. Now, this situation will instead be given a status of 200, despite the lack
of data. This is useful for interaction with certain APIs.

Previously, the onload and onerror callbacks were added to the JSONP script tag. These have been
replaced with jQuery events, in order to gain access to the event object. This means that it is now
difficult to test if the callbacks are registered or not. This is possible with jQuery, using the
$.data("events") method, however it is currently impossible with jqLite. This is not expected to
break applications.

Closes angular#4987
Closes angular#6735
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$http.jsonp fails when the response body is empty
3 participants