diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 0a0e1f71680e..3c40c5d168be 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -1,5 +1,15 @@ 'use strict'; +// We need to be able to detect IE8 so we can use the right AJAX method below +var ie = (function(v, p, needle, undef) { + needle = p.getElementsByTagName('br'); + while( + p.innerHTML = '', + needle[0] + ); + return v > 4 ? v : undef; +})(3, document.createElement('p')); + var XHR = window.XMLHttpRequest || function() { /* global ActiveXObject */ try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e1) {} @@ -7,6 +17,15 @@ var XHR = window.XMLHttpRequest || function() { try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e3) {} throw minErr('$httpBackend')('noxhr', "This browser does not support XMLHttpRequest."); }; +// Fix for IE8's native XMLHttpRequest not supporting PATCH +if (ie === 8) { + XHR = function (method) { + if (method === 'PATCH') { + return new ActiveXObject('Microsoft.XMLHTTP'); + } + return new window.XMLHttpRequest(); + }; +} /** diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index 8c843d2add07..a16e9e1d330c 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -75,6 +75,15 @@ describe('$httpBackend', function() { expect(xhr.$$data).toBe(null); }); + it('should use ActiveXObject for PATCH on IE8', function () { + xhr = new XHR('PATCH'); + if (msie <= 8) { + expect(function() {xhr.toString();}).toThrow(); + } else { + expect(xhr.toString()).toMatch(/\[object .+\]/); + } + }); + it('should normalize IE\'s 1223 status code into 204', function() { callback.andCallFake(function(status) { expect(status).toBe(204);