I've put together a demonstration using JavaScript to interact with the Flickr photo search API. Now, I'm in the process of transitioning it to AngularJs, and after some research online, I have come across the following configuration:
Configuration:
myApp.config(function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
Service:
myApp.service('dataService', function($http) {
delete $http.defaults.headers.common['X-Requested-With'];
this.flickrPhotoSearch = function() {
return $http({
method: 'GET',
url: 'http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=3f807259749363aaa29c76012fa93945&tags=india&format=json&callback=?',
dataType: 'jsonp',
headers: {'Authorization': 'Token token=xxxxYYYYZzzz'}
});
}
});
Controller:
myApp.controller('flickrController', function($scope, dataService) {
$scope.data = null;
dataService.flickrPhotoSearch().then(function(dataResponse) {
$scope.data = dataResponse;
console.log($scope.data);
});
});
Despite implementing these changes, I'm still encountering the same error message. In my attempts to solve this issue, I explored some helpful resources:
XMLHttpRequest cannot load URL. Origin not allowed by Access-Control-Allow-Origin
http://samurails.com/tutorial/cors-with-angular-js-and-sinatra/