1

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

});
1
  • Did you the check the http response ? Commented Oct 17, 2014 at 7:49

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Sven, thanks for your reply. i modified the source codes by your suggestion, but still could not get the data returned. the status is '0'..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.