javascript - 使用 AngularJS 发送 GET 请求时无法从 WebStorm IDE 执行 'open' 无效 URL

标签 javascript node.js angularjs cors webstorm

我启用了 CORS 模块并在我的 nodeJS 服务器代码中设置了所需的选项。我能够将 GET 请求从我的浏览器发送到给定的 URL 并获得响应。但是,当我尝试执行以下代码以使用来自 WebStorm IDE 内置服务器的以下 AngularJS 代码发送 GET 请求时,出现以下错误。

city name Delhi
error SyntaxError: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL

代码如下。

mainApp.controller('dController', function($scope,$http) {
    this.ccaid = {
        city:'',
        circle:'',
        area:'',
    };
    this.getCircle=function(){
        console.log('city name ' + this.ccaid.city);
        $http({
            method: 'GET',
            crossDomain:true,
            url: 'xx.xxx.xx.xx:3000/fetchCityArea',
            params:{city:this.ccaid.city}
        }).then(function(success){
            console.log('response ' + success);
        },function(error){
            console.log('error ' + error);
        });
    };
});

URL 没有问题,但仍然无法发送 GET 请求。

如何解决?

最佳答案

您的网址是否包含方案?您的示例代码没有:

url: 'xx.xxx.xx.xx:3000/fetchCityArea',

那需要有scheme部分——http://https://:

url: 'https://xx.xxx.xx.xx:3000/fetchCityArea',

关于javascript - 使用 AngularJS 发送 GET 请求时无法从 WebStorm IDE 执行 'open' 无效 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42247444/

相关文章:

javascript - 将鼠标悬停在一个 div 上并更改另一 div 的背景

javascript - 获取状态 -1 而不是 401 Angularjs

sockets - socket.emit()与socket.send()

javascript - 为什么这个简单的导出在 NodeJS 中给我错误?

javascript - 有什么方法可以通过单击外部来关闭 Angular UI 工具提示吗?

javascript - 如何使用 jquery 请求 requirejs 模块?

javascript - 有没有更简单的方法来更新复选框价格?

node.js - Webstorm 和睾丸整合

angularjs - 如何用 Angular 重置表单

javascript - 窗口 innerWidth 大小更改时的 AngularJS 事件