0
我試圖從flickr服務this one中檢索一些圖像。 不幸的是,我有以下錯誤:
XMLHttpRequest cannot load http://api.flickr.com/services/feeds/photos_public.gne?format=json.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:3000' is therefore not allowed access.
這裏是我的代碼:
angular.module('myApp')
.service('getFlickrImages', function($http){
this.getData = function() {
delete $http.defaults.headers.common['X-Requested-With'];
return $http({
method: 'GET',
url: 'http://api.flickr.com/services/feeds/photos_public.gne?format=json'
});
}
});
angular.module('myApp')
.controller('MainCtrl', function ($scope, getFlickrImages) {
$scope.data = null;
getFlickrImages.getData().then(function(dataResponse) {
$scope.data = dataResponse;
});
});
這裏有一個Plunker如果有人能幫助我
這不是關於你的代碼,這個錯誤消息意味着API服務器不允許你使用它。嘗試找到關於在文檔中測試的東西,也許他們打開了它的路線 – ThomasP1988
我嘗試沒有在純JavaScript的角度,它的工作 – adam
當你在純JavaScript嘗試它,你執行它在http:// localhost:3000或只需使用瀏覽器? – ThomasP1988