Skip to content

Commit 331d74b

Browse files
committed
readystatechange works better in IE11
1 parent 1aaab5b commit 331d74b

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/xhr.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ export function xhrImpl(url, { method, headers, body, onNext, onError, onComplet
1818

1919
const patchResolver = new PatchResolver({ onResponse: r => onNext(r) });
2020

21-
function onProgressEvent() {
22-
if (isDeferred) {
23-
const chunk = xhr.response.substr(index);
24-
patchResolver.handleChunk(chunk);
25-
index = xhr.responseText.length;
26-
}
27-
}
28-
2921
function onReadyStateChange() {
3022
if (this.readyState === this.HEADERS_RECEIVED) {
3123
const contentType = xhr.getResponseHeader('Content-Type');
3224
if (contentType.indexOf('multipart/mixed') >= 0) {
3325
isDeferred = true;
3426
}
27+
} else if (
28+
(this.readyState === this.LOADING || this.readyState === this.DONE) &&
29+
isDeferred
30+
) {
31+
const chunk = xhr.response.substr(index);
32+
patchResolver.handleChunk(chunk);
33+
index = xhr.responseText.length;
3534
} else if (this.readyState === this.DONE && !isDeferred) {
3635
onNext(JSON.parse(xhr.response));
3736
onComplete();
@@ -57,7 +56,6 @@ export function xhrImpl(url, { method, headers, body, onNext, onError, onComplet
5756
}
5857

5958
xhr.addEventListener('readystatechange', onReadyStateChange);
60-
xhr.addEventListener('progress', onProgressEvent);
6159
xhr.addEventListener('loaded', onLoadEvent);
6260
xhr.addEventListener('error', onErrorEvent);
6361
xhr.send(body);

0 commit comments

Comments
 (0)