AngularJS $http.get service

时间:2015-07-28 22:43:27

标签: javascript angularjs

I'm using a $http.get service in my app, which is retrieving xml data for conversion. In my plnkr I also have a file named data.xml which has the same formatted xml file as in the url I entered. When I enter data.xml into the $http.get function, the data is received and my app works. When I try plugging in the url, however, it crashes. The browser tells me that I have an illegal token on the line with the url. I've looked over the documentation on the angularjs site and I can't find why I'm getting this error. I'm new to angular and don't have much experience with this service. How can I pull the data from that url?

My current code:

factory('DataSource', ['$http', function($http) {
    return {
        get: function() {
            return $http.get(
                'http://50.22.49.237/XMLFiles/ReformatedSample.xml', {
                    transformResponse: function(data) {
                        var x2js = new X2JS();
                        var json = x2js.xml_str2json(data);
                        return json;
                    }
                }
            )
            success(function(data, status) {
                callback(data);
            })
        }
    }
}]);

Any help is appreciated.

1 个答案:

答案 0 :(得分:0)

Have you checked the console? Maybe you have a CORS issue.