From 3ae3ccf3dab95793c868d626a4560aacf3cae796 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Thu, 18 Aug 2011 23:43:25 +0200 Subject: fix($browser.xhr): fix IE6, IE7 bug - sync xhr when serving from cache IE6, IE7 is sync when serving content from cache. We want consistent api, so we have to use setTimeout to make it async. --- src/service/browser.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/service/browser.js') diff --git a/src/service/browser.js b/src/service/browser.js index 49bfe99e..b38c9211 100644 --- a/src/service/browser.js +++ b/src/service/browser.js @@ -73,6 +73,11 @@ function Browser(window, document, body, XHR, $log, $sniffer) { } } + // normalize IE bug (http://bugs.jquery.com/ticket/1450) + function fixStatus(status) { + return status == 1223 ? 204 : status; + } + /** * @ngdoc method * @name angular.module.ng.$browser#xhr @@ -120,14 +125,22 @@ function Browser(window, document, body, XHR, $log, $sniffer) { forEach(headers, function(value, key) { if (value) xhr.setRequestHeader(key, value); }); - xhr.onreadystatechange = function() { - if (xhr.readyState == 4) { - // normalize IE bug (http://bugs.jquery.com/ticket/1450) - var status = xhr.status == 1223 ? 204 : xhr.status; - completeOutstandingRequest(callback, status, xhr.responseText); - } - }; + xhr.send(post || ''); + + // IE6, IE7 bug - does sync when serving from cache + if (xhr.readyState == 4) { + setTimeout(function() { + completeOutstandingRequest(callback, fixStatus(xhr.status), xhr.responseText); + }, 0); + } else { + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + completeOutstandingRequest(callback, fixStatus(xhr.status), xhr.responseText); + } + }; + } + return xhr; } }; -- cgit v1.2.3