From 37387981df4f432ee0f6a1cabfb2f6922e147e57 Mon Sep 17 00:00:00 2001 From: Jeff Schenck Date: Thu, 12 Dec 2013 13:33:00 -0800 Subject: [PATCH 1/2] test($httpBackend): add test for using ActiveXObject in IE8 for PATCH operations In Internet Explorer 8, the native XMLHttpRequest object does not allow the HTTP PATCH method. This tests that in IE8, when performing a PATCH, we fall back to ActiveXObject. --- test/ng/httpBackendSpec.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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); From 397dc108de495775aa60ccc4e4f248712d1a3a71 Mon Sep 17 00:00:00 2001 From: Jeff Schenck Date: Thu, 12 Dec 2013 13:36:40 -0800 Subject: [PATCH 2/2] fix($httpBackend): fix HTTP PATCH requests in IE8 In Internet Explorer 8, the native XMLHttpRequest object does not allow the HTTP PATCH method. In order to accomplish a PATCH, you need to use the ActiveX object. Update the default XHR to use the ActiveX object when doing a PATCH in IE8. See the following for documentation: http://blogs.msdn.com/b/ieinternals/archive/2009/07/23/the-ie8-native-xmlhttprequest-object.aspx http://bugs.jquery.com/ticket/13240 --- src/ng/httpBackend.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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(); + }; +} /**