diff --git a/docs/content/error/httpBackend/noxhr.ngdoc b/docs/content/error/httpBackend/noxhr.ngdoc new file mode 100644 index 000000000000..e2d5901d72ea --- /dev/null +++ b/docs/content/error/httpBackend/noxhr.ngdoc @@ -0,0 +1,10 @@ +@ngdoc error +@name $httpBackend:noxhr +@fullName Unsupported XHR +@description + +This error occurs in browsers that do not support XmlHttpRequest. AngularJS +supports Safari, Chrome, Firefox, Opera, IE8 and higher, and mobile browsers +(Android, Chrome Mobile, iOS Safari). To avoid this error, use an officially +supported browser. + diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index f52e461157f0..665c5eec3997 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -1,13 +1,18 @@ 'use strict'; function createXhr(method) { - // IE8 doesn't support PATCH method, but the ActiveX object does - /* global ActiveXObject */ - return (msie <= 8 && lowercase(method) === 'patch') - ? new ActiveXObject('Microsoft.XMLHTTP') - : new window.XMLHttpRequest(); -} + //if IE and the method is not RFC2616 compliant, or if XMLHttpRequest + //is not available, try getting an ActiveXObject. Otherwise, use XMLHttpRequest + //if it is available + if (msie <= 8 && (!method.match(/^(get|post|head|put|delete|options)$/i) || + !window.XMLHttpRequest)) { + return new ActiveXObject("Microsoft.XMLHTTP"); + } else if (window.XMLHttpRequest) { + return new window.XMLHttpRequest(); + } + throw minErr('$httpBackend')('noxhr', "This browser does not support XMLHttpRequest."); +} /** * @ngdoc object