diff options
| author | Vojta Jina | 2011-08-18 23:43:25 +0200 |
|---|---|---|
| committer | Igor Minar | 2011-11-30 11:03:42 -0500 |
| commit | 3ae3ccf3dab95793c868d626a4560aacf3cae796 (patch) | |
| tree | c199b2f45b729f9858a9ab153c35c15f1ee237ba /src/service/browser.js | |
| parent | e9b57f9df8eb4aaa2c1657d303c78dc68828091b (diff) | |
| download | angular.js-3ae3ccf3dab95793c868d626a4560aacf3cae796.tar.bz2 | |
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.
Diffstat (limited to 'src/service/browser.js')
| -rw-r--r-- | src/service/browser.js | 27 |
1 files changed, 20 insertions, 7 deletions
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; } }; |
