Krishan Krishan - 6 months ago 35
AngularJS Question

Error: window.XMLhttpRequest is not a constructor in angular

I am getting this error when I try to get data using

$http.get
. I have tracked the error and found out that this is caused because
window.XMLhttpRequest
is undefined inside angular.js line 11520.

Error: window.XMLhttpRequest is not a constructor
createXhr@https://localhost:61452/scripts/angular.js:11520:14
createhttpBackend/<@https://localhost:61452/scripts/angular.js:11568:17
sendReq@https://localhost:61452/scripts/angular.js:11423:9
$http/serverRequest@https://localhost:61452/scripts/angular.js:11133:16
processQueue@https://localhost:61452/scripts/angular.js:15758:28
scheduleProcessQueue/<@https://localhost:61452/scripts/angular.js:15774:27
$RootScopeProvider/this.$get</Scope.prototype.$eval@https://localhost:61452/scripts/angular.js:17026:16
$RootScopeProvider/this.$get</Scope.prototype.$digest@https://localhost:61452/scripts/angular.js:16842:15
$RootScopeProvider/this.$get</Scope.prototype.$apply@https://localhost:61452/scripts/angular.js:17134:13
bootstrapApply@https://localhost:61452/scripts/angular.js:1713:9
invoke@https://localhost:61452/scripts/angular.js:4625:16
bootstrap/doBootstrap@https://localhost:61452/scripts/angular.js:1711:5
bootstrap@https://localhost:61452/scripts/angular.js:1731:12
@https://localhost:61452/App/app.js:318:5
newContext/context.execCb@https://localhost:61452/scripts/require.js:1693:24
newContext/Module.prototype.check@https://localhost:61452/scripts/require.js:881:43
newContext/Module.prototype.enable@https://localhost:61452/scripts/require.js:1173:17
newContext/Module.prototype.init@https://localhost:61452/scripts/require.js:786:21
callGetModule@https://localhost:61452/scripts/require.js:1200:17
newContext/context.completeLoad@https://localhost:61452/scripts/require.js:1587:21
newContext/context.onScriptLoad@https://localhost:61452/scripts/require.js:1714:21


I'm using require js to load my dependencies

require.config({
paths: {
'angular': '/scripts/angular',
'angular-ui-router': '/scripts/angular-ui-router.min',
'bootstap': '/scripts/bootstrap.min',
'jqueryDropDownStyle': '/scripts/custom/jquery.ddslick.min',
'ddsclickFunctions': '/scripts/custom/ddsclickFunctions',
'timerFunctions': '/scripts/custom/Timer',
'chatWidgetSettingsFunc':'/scripts/custom/chatWidgetSettingsFunc',
'angular-resource': '/scripts/angular-resource.min',
'jquery.flagstrap': '../../scripts/jquery.flagstrap',
'angular-sanitize': '/scripts/angular-sanitize.min',
'angular-cookies': '/scripts/angular-cookies.min',
'angular-locale_en': '/scripts/i18n/angular-locale_en',
'angular-locale_ar': '/scripts/i18n/angular-locale_ar',
'jquery': '/scripts/jquery-1.12.3.min',
'jquery-ui': '/scripts/jquery-ui-1.11.4',
'bootstrap-color': '/scripts/custom/bootstrap-colorpicker',
'ui-bootstrap-tpls': '/scripts/angular-ui/ui-bootstrap-tpls',
'ui-bootstrap': '/scripts/angular-ui/ui-bootstrap',
'ngAnimate': '/scripts/angular-animate',
'icolorPicker': '/scripts/custom/iColorPicker',
'signalr': '/scripts/jquery.signalR-2.2.0.min',
'hubs': '/signalr/hubs?',
'directives': '/App/common/directives',
'servicers': '/App/common/servicers',
'api': 'https://www.google.com/recaptcha/api',
'react': 'react-15.0.2',
'reactDom': 'react-dom-15.0.2',
'moment': '/scripts/moment',
'momentData': '/scripts/moment-timezone-with-data',
'editor': '/scripts/editor',
'ckeditor':'/Content/plugins/ckeditor/ckeditor',
'config': '/App/config',
'app': '/App/app'
},

shim: {

'angular': {
deps: ['jquery']
},
'angular-ui-router': {
deps: ['angular']
},
'angular-resource': {
deps: ['angular']
},
'jquery.flagstrap': {
deps: ['jquery']
},
'jquery-ui':{
deps: ['jquery'],
},
'bootstap': {
deps: ['jquery']
},
'angular-sanitize': {
deps: ['angular']
},
'angular-cookies': {
deps: ['angular']
},
'angular-locale_en': {
deps: ['angular']
},
'angular-locale_ar': {
deps: ['angular']
},
'ui-bootstrap': {
deps: ['bootstap', 'angular']
},
'signalr': {
deps: ['jquery'],
exports: "$.connection"
},
'hubs': {
deps: ['signalr']
},
'bootstrap-color': {
deps: ['bootstap']
},
'jqueryDropDownStyle': {
deps: ['jquery']
},
'chatWidgetSettingsFunc': {
deps: ['angular','jquery']
},
'timerFunctions': {
deps: ['jquery']
},
'editor': {
deps: ['jquery', 'bootstap']
},
'ddsclickFunctions': {
deps: ['jquery']
},
'icolorPicker': {
deps: ['jquery']
},
'directives': {
deps: ['angular']
},
'servicers': {
deps: ['angular']
},
'ngAnimate': {
deps: ['angular']
},
'ui-bootstrap-tpls': {
deps: ['bootstap', 'angular']
},
'app': {
deps: ['angular', 'angular-ui-router', 'bootstap', 'bootstrap-color', 'angular-resource', 'jquery.flagstrap', 'angular-sanitize', 'angular-cookies', 'angular-locale_en', 'angular-locale_ar', 'jqueryDropDownStyle', 'ddsclickFunctions', 'chatWidgetSettingsFunc', 'directives', 'servicers', 'timerFunctions', 'config', 'hubs', 'ui-bootstrap', 'editor', 'jquery-ui', 'react', 'reactDom', 'moment', 'momentData', 'ngAnimate', 'ui-bootstrap-tpls', 'ckeditor']
},


}
});


I'm using https for all communications.

Answer

Update the angular js to latest https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js