aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/httpBackend.js
diff options
context:
space:
mode:
authorPete Bacon Darwin2013-11-22 13:22:41 +0000
committerPete Bacon Darwin2013-11-22 13:45:55 +0000
commita3172a285fd74b5aa6c8d68a4988c767c06f549c (patch)
tree74f9be8010b71c43aea3f3232600f295fc58c23b /src/ng/httpBackend.js
parent84c408ce63859e81fb4e900683edcc0cb8188890 (diff)
downloadangular.js-a3172a285fd74b5aa6c8d68a4988c767c06f549c.tar.bz2
fix($httpBackend): only IE8 and below can't use `script.onload` for JSONP
IE8, IE9 and IE10 can use `script.onreadystate` so up till now we have been using this if the sniffer says we are on IE. But IE11 now does not support `script.onreadystate` and only supports the more standard `script.onload` and `script.onerror`. IE9 and IE10 do support `script.onload` and `script.onerror`. So now we only test whether we are on IE8 or earlier before using `script.onreadystate`. See http://pieisgood.org/test/script-link-events/ jQuery just uses all these handlers at once and hopes for the best, but since IE9 and IE10 support both sets of handlers, this could cause the handlers to be run more than once. jQuery also notes that there is a potential memory leak in IE unless we remove the handlers from the script object once they are run. So we are doing this too, now. Closes #4523 Closes #4527 Closes #4922
Diffstat (limited to 'src/ng/httpBackend.js')
-rw-r--r--src/ng/httpBackend.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js
index 5496589b..3982fad0 100644
--- a/src/ng/httpBackend.js
+++ b/src/ng/httpBackend.js
@@ -136,6 +136,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
// - adds and immediately removes script elements from the document
var script = rawDocument.createElement('script'),
doneWrapper = function() {
+ script.onreadystatechange = script.onload = script.onerror = null;
rawDocument.body.removeChild(script);
if (done) done();
};
@@ -143,12 +144,16 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
script.type = 'text/javascript';
script.src = url;
- if (msie) {
+ if (msie && msie <= 8) {
script.onreadystatechange = function() {
- if (/loaded|complete/.test(script.readyState)) doneWrapper();
+ if (/loaded|complete/.test(script.readyState)) {
+ doneWrapper();
+ }
};
} else {
- script.onload = script.onerror = doneWrapper;
+ script.onload = script.onerror = function() {
+ doneWrapper();
+ };
}
rawDocument.body.appendChild(script);