-1
getjson.controller('controller', function($scope, $http){
  var url = "http://api.8coupons.com/v1/getsubcategory"; 

  $http.get(url).success(function(data, status, headers, config){
    $scope.jsondata = data;
    console.log(data);
  }).error(function(data, status, headers, config){});
});

(ed's note: added a closing brace to the outer function body.)

This code gives me the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.api.8coupons.com/v1/getsubcategory. This can be fixed by moving the resource to the same domain or enabling CORS.

Can somebody please tell me what is wrong and how can I fix this?

Peter Lewerin
  • 13,140
  • 1
  • 24
  • 27
PDJ
  • 69
  • 8
  • 1
    [Check this search....](https://www.google.co.in/search?q=enabling+CORS&oq=enabling+CORS&aqs=chrome..69i57&sourceid=chrome&es_sm=93&ie=UTF-8) – Jai Nov 13 '14 at 07:20

1 Answers1

2

I found out an answer.

var url = "http://api.8coupons.com/v1/getcategory?callback=JSON_CALLBACK";

May be it can help someone.

If you get this kind of error change the type from get/post to jsonp

and then in url append this parameter

 "?callback=JSON_CALLBACK" 

without quotes

PDJ
  • 69
  • 8
  • It does work. Checkout http://stackoverflow.com/a/13400409/1629696 for a more detailed solution. – odedfos Dec 06 '14 at 17:31