在使用AngularJS发送GET请求时,无法从WebStorm IDE执行“打开”无效URL

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

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是否包含计划? 您的示例代码不:

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

这需要有一个scheme部分 – http://https://

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

除了sideshowbarker的答案 –

url应该是WHATWG URL标准。 有效的URL格式的例子在这里 – https://url.spec.whatwg.org/#example-url-parsing