Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to execute 'open' invalid URL from WebStorm IDE while sending GET request using AngularJS

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

Code is as follows.

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

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

How can it be resolved?

like image 774
Satya Narayana Avatar asked Sep 03 '25 09:09

Satya Narayana


1 Answers

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

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

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

url: 'https://xx.xxx.xx.xx:3000/fetchCityArea',
like image 169
sideshowbarker Avatar answered Sep 05 '25 01:09

sideshowbarker