javascript - 错误: window. XMLhttpRequest不是 Angular 中的构造函数

标签 javascript angularjs https requirejs

当我尝试使用 $http.get 获取数据时,出现此错误。我跟踪了该错误,发现这是因为 window.XMLhttpRequest 在 angular.js 第 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

我正在使用 require js 加载我的依赖项

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']
        },


    }
});

我使用 https 进行所有通信。

最佳答案

将 Angular js 更新到最新版本https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js

关于javascript - 错误: window. XMLhttpRequest不是 Angular 中的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37339324/

相关文章:

javascript - 将数组作为查询字符串传递

AngularJs (ui.router) & Crawlers - `!#` 是否改善了 SEO?

javascript - 如何在Angular中获取#之前的路径

ruby-on-rails - ruby 代码在模板中显示为 html

http - 为什么要检测 HTTP 协议(protocol)而不是仅使用 '//' 链接内容,如 JS、AJAX、CSS 等?

javascript - 使图像占屏幕的百分比而不是像素?

javascript - 如何在 React 中动态分配属性?

本地主机上的 Spring Boot HTTPS

javascript - PHP - 使用 `file_get_contents()` 插入 javascript

javascript - 是否可以将事件链接到对象自己的参数?