请求的资源上没有“Access-Control-Allow-Origin”标头 - 错误

时间:2015-07-01 13:10:05

标签: angularjs

我正在尝试从instagram获取JSON文件,当我创建$ http.get时出现错误:

insta.ctrl:

Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"

我的apache2的conf

XMLHttpRequest cannot load #url_of_intagram_api_here. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access.

Chrome上的错误消息:

~

当我在Chrome中禁用互联网安全时,它可以正常工作。 有任何想法吗?

1 个答案:

答案 0 :(得分:1)

显然Instagram API没有实现CORS。但是,它们为数据检索提供了JSONP接口。所以你可以做的是使用jsonp方法:

double d = (2*100)/3

注意$http.jsonp('http://api.instagram.com/publicapi/oembed/?url=http://instagr.am/p/fA9uwTtkSN/&callback=JSON_CALLBACK').success(function(data) { $scope.data = data; }); 您需要发送的GET参数。

演示: http://plnkr.co/edit/OG1sT7A9OM1hWBqCvSmC?p=preview