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

Commit 431bad0

Browse files
committed
fix($http): ignore xhr.responseType setter exception if value is "json"
WebKit added support for the json responseType value on 09/03/2013 https://bugs.webkit.org/show_bug.cgi?id=73648. Versions of Safari prior to 7 are known to throw when setting the value "json" as the response type. Other older browsers implementing the responseType. Other browsers with infrequent update cycles may also be affected. The json responseType value can be ignored if not supported, because JSON payloads are parsed on the client-side regardless. Closes #6115 Closes #6122
1 parent 5850e61 commit 431bad0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/ng/httpBackend.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,21 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
106106
xhr.withCredentials = true;
107107
}
108108

109-
if (responseType) {
110-
xhr.responseType = responseType;
109+
if (responseType && isString(xhr.responseType)) {
110+
try {
111+
xhr.responseType = responseType;
112+
} catch (e) {
113+
// WebKit added support for the json responseType value on 09/03/2013
114+
// https://bugs.webkit.org/show_bug.cgi?id=73648. Versions of Safari prior to 7 are
115+
// known to throw when setting the value "json" as the response type. Other older
116+
// browsers implementing the responseType
117+
//
118+
// The json response type can be ignored if not supported, because JSON payloads are
119+
// parsed on the client-side regardless.
120+
if (responseType !== 'json') {
121+
throw e;
122+
}
123+
}
111124
}
112125

113126
xhr.send(post || null);

0 commit comments

Comments
 (0)