使用AngularJS发送GET请求时,无法从WebStorm IDE执行“打开”无效URL [英] Failed to execute 'open' invalid URL from WebStorm IDE while sending GET request using AngularJS

查看:527
本文介绍了使用AngularJS发送GET请求时,无法从WebStorm IDE执行“打开”无效URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I enabled CORS module and set required options in my nodeJS server code. I am able to send the GET request from my browser to the given URL and getting response. But when I am trying to execute below code for sending a GET request using following AngularJS code from WebStorm IDE's built-in server I am getting below error.

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);
        });
    };
});

网址没有任何问题,但仍然无法发送GET请求。

There is nothing wrong with the URL but still it is unable to send GET request.

如何解决?

推荐答案

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

Does your URL include a scheme? Your example code doesn’t:

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

需要有一个方案部分 - http:// https://

That needs to have a scheme part—http:// or https://:

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

这篇关于使用AngularJS发送GET请求时,无法从WebStorm IDE执行“打开”无效URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆