Reputation: 43
My first time with http request. I use Angular for it. Server works normal - it's public news API. I need to get JSON file by URL like "hostname.com/article/2014/06/10/123?api-key=1234567890".
function Ctrl($scope, $http, $templateCache) {
//some code there
$scope.load_article = function( patch ) {
$http.get(patch + "?" + $scope.apikey)
.success(function(response){
result = angular.fromJson(response.data);
$scope.article = result;
}).error(function(response) {
$scope.article = "error "+ response.status;
});
};
}
But when i call load_article() tracer shows me that result:
Method: OPTIONS;
Status: 596 OK;
Type: text/xml;
and "error undefined" into $scope.article.
Where is my fault?
Upd:
$http.jsonp(patch + "?" + $scope.apikey).success(function(data)){...}
Will be better for get JSON file.
Upvotes: 1
Views: 903
Reputation: 4458
JSONP usually requires you to send a callback function in your request (you should look up the documentation for the api). If you'd tell us what public news API you're using, someone might help.
Upvotes: 2