From cd735c483747c66d378ae34f4755178dd0a54d70 Mon Sep 17 00:00:00 2001 From: gdi2290 Date: Tue, 16 Jun 2015 23:15:26 -0700 Subject: [PATCH] fix(XHRImpl): file:/// and IE9 bugs --- modules/angular2/src/render/xhr_impl.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/angular2/src/render/xhr_impl.ts b/modules/angular2/src/render/xhr_impl.ts index 71b61f2451..00c779162f 100644 --- a/modules/angular2/src/render/xhr_impl.ts +++ b/modules/angular2/src/render/xhr_impl.ts @@ -11,9 +11,22 @@ export class XHRImpl extends XHR { xhr.responseType = 'text'; xhr.onload = function() { - var status = xhr.status; + // responseText is the old-school way of retrieving response (supported by IE8 & 9) + // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) + var response = ('response' in xhr) ? xhr.response : xhr.responseText; + + // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) + var status = xhr.status === 1223 ? 204 : xhr.status; + + // fix status code when it is 0 (0 status is undocumented). + // Occurs when accessing file resources or on Android 4.1 stock browser + // while retrieving files from application cache. + if (status === 0) { + status = response ? 200 : 0; + } + if (200 <= status && status <= 300) { - completer.resolve(xhr.responseText); + completer.resolve(response); } else { completer.reject(`Failed to load ${url}`, null); }