How to make cross site HTTP GET JSON request

381 views Asked by At

I am using AngularJS to make a cross site json call as following:

$http.get('http://ipinfo.io/json').success(function(response){

The above request works fine for Chrome and Mozilla Forefox, but it doesn't work on IE 9. IE 9 is the only version I've tested it on. I am assuming it wouldn't work on other IE versions either.

Could somebody tell me the mistake I am committing here for its not working in IE 9?

1

There are 1 answers

6
GeekOnGadgets On

enter image description here This is how I do it and this does not through any errors for me. Hope this can fix your problem.

//controller

(function() {
    var ipInfo = function($scope,IPService){
        IPService.ipServiceProvider()
         .success(function(data){
          console.log(data);
       })
         .error(function(status,error){
           console.log(status);
           console.log(data);
       })
    };
    ipInfo.$inject = ['$scope',IPService];
    angular.module('app').controller('ipInfo',ipInfo);
}());

//services

 (function() {
    var IPService= function($http) {
        var urlBase = "http://ipinfo.io/json";
        var factory = {};
        factory.ipServiceProvider= function() {
            return $http.get(urlBase);
        };
        return factory;
    };
    IPService.$inject = ['$http'];
    angular.module('app').factory('IPService',IPService);
}());

Please let me know if you have any problems

Update : If you see this screen click on Yes. This usually pops up in IE8 and IE9.