0

I'm having trouble to load some data from a web service. I created this factory:

.factory('urlService', function($http) {
  var service = {
  getURLStatus: function(urlElgg){
    var urlElgg = 'http://'+urlElgg+'/services/api/rest/xml/?method=system.api.list';
    $http({method: 'GET', url: urlElgg}).
      success(function(data) {
        console.log("success");
      }).
      error(function(data) {
        console.log("error");
      });
    }
  };
  return service;
})

And I have this in the controller:

  $scope.doAddCommunity = function() {
    console.log('Doing Add Community', $scope.communityData.url);
    urlService.getURLStatus($scope.communityData.url);
  };

Everything looks OK, but when I send an url always get "error" instead of "success". What I am doing wrong?

11
  • What is the error message you are getting ? Try using angular.toJson(data) in the console.log() on the Error callback and post the error message here. Commented Oct 6, 2014 at 9:03
  • I'm not receiving any error message, only the code goes to the error part of the $http function, so I receive the string "error" as the result. Commented Oct 6, 2014 at 9:12
  • Please do what @jsfrocha said, replace console.log("error") with console.log(data) and tell us what you get in the console. Commented Oct 6, 2014 at 9:25
  • You are not receiving any error message because you are not "asking" for it. If the code "goes to the error part" it also receives a data object, which you can log by doing console.log(angular.toJson(data)) in that part and checking its value in the browser console. Commented Oct 6, 2014 at 9:26
  • When I do that the only that I get is an empty result "" Commented Oct 6, 2014 at 9:30

1 Answer 1

2

What you have is cross-domain request problem. In order to understand it, please take a moment to read the Same-origin policy.

Since you are not able to do the request "as it is", it means CORS is not enabled. Your other option is to use JSONP, however I don't think JSONP is currently supported by the app.coldtrick.com API.

Unless one of these options is enabled on the server-side, you will not be able to do those requests directly from the JS application.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.