-1

through AngularJs'm trying to access a server to make me return a JSON in thi way

modulo.controller('listaController', function($scope, $http) {
    $http.get('http://api.rottentomatoes.com/api/public/v1.0/movies.json?[apyKeyBlaBla]&q=Toy+Story+3&page_limit=1').success(function(data) {
        $scope.items = data;
    });
});

but when you launch the application I get this error:

XMLHttpRequest cannot load [Name Sting] No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8383' is therefore not allowed access.

Where is the solution? Notified that I use netbeans and I put my apyKey in the above string then the string is correct because I tested it!

Alessandro
  • 905
  • 3
  • 17
  • 32
  • See the post in this .. you will get some idea from here http://stackoverflow.com/questions/29466380/how-to-add-res-addheaderaccess-control-allow-origin-in-express-js/29466458#29466458 – Reena Apr 08 '15 at 18:35

3 Answers3

1

You should do something like this:

$http.jsonp('http://api.rottentomatoes.com/api/public/v1.0/movies.json?[apyKeyBlaBla]&q=Toy+Story+3&page_limit=1&callback=JSON_CALLBACK').success(function(data) {
    $scope.items = data;
});

Important is to have callback=JSON_CALLBACK in the request url

Rise Ledger
  • 949
  • 7
  • 11
0

This error is raised because browsers does not allow to make AJAX request from one host (localhost) to another host (rottentomatoes.com) unless the later permits so. This is known as CORS.

The only way you may accomplish this is to use a gateway between your AJAX code and rottentomatoes.com. e.i. Make the AJAX request to a backend app you wrote and let the later make the actual request to rottentomatoes.com returning the result to your cleint application.

Christopher Ramírez
  • 1,710
  • 10
  • 13
-1

"You are doing an XMLHttpRequest to a different domain than your page is on. So the browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do something different when you want to do a cross-domain request." by @MD. Sahib Bin Mahboob

I suggest you reading this question/answers:

"No 'Access-Control-Allow-Origin' header is present on the requested resource"

Community
  • 1
  • 1
andybeli
  • 836
  • 7
  • 14