Sinntar
Sinntar

Reputation: 11

angular $http always return status 0

I am using the angular $http to call the webservice, but i can not get any data from service, the status is always 0,

var httpurl = "http://127.0.0.1:3000?orderCode=700501898";


var myApp = angular.module('piechart', []);


myApp.factory('MyService', ['$http', function ($http) {
    return new function () {

        this.GetName = function () {
            return $http({
                url: httpurl,
                method:'GET'
            })
        };
    };
}]);
   angular.injector(['ng', 'piechart']).invoke(function (MyService) {

    MyService.GetName();

});

Upvotes: 1

Views: 115

Answers (1)

Sven Schürmann
Sven Schürmann

Reputation: 612

Why did you encapsulate $http service twice?

var httpurl = "http://127.0.0.1:3000?orderCode=700501898";


var myApp = angular.module('piechart', []);


myApp.factory('MyService', ['$http', function ($http) {
    return {

        GetName:function () {
            return $http({
                url: httpurl,
                method:'GET'
            })
        }
    };
}]);

   angular.injector(['ng', 'piechart']).invoke(function (MyService) {

    MyService.GetName();

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

Upvotes: 1

Related Questions