问题描述
我有简单的网站我与它要求JSON数据的API AngularJS建设。
不过我正跨域起源问题反正有这个问题,才能允许跨域请求?
错误:
XMLHtt prequest无法加载<一个href=\"http://api.nestoria.co.uk/api?country=uk&$p$ptty=1&action=search_listings&place_name=soho&encoding=json&listing_type=rent\">http://api.nestoria.co.uk/api?country=uk&$p$ptty=1&action=search_listings&place_name=soho&encoding=json&listing_type=rent.无访问控制允许来源标头的请求的资源present。产地:所以访问http // localhost'的是不允许的访问。
searchByPlaceName:功能(){
VAR URL = baseURL时+'=国家英国和放大器; pretty = 1&安培;行动= search_listings&安培; PLACE_NAME =伦敦'+编码+型;
返回$ http.get(URL);
}
似乎 api.nestoria.co.uk
不允许CORS。它设置访问控制允许来源
头本身 - 您对没有直接控制
不过,您可以使用JSONP。该网站允许它通过回调
查询参数。
+编码+型+&放大器;回调= JSON_CALLBACK)
I have simple website I'm building with AngularJS which calls an API for json data.
However I am getting Cross domain origin problem is there anyway around this to allow for cross domain requests?
Error:
XMLHttpRequest cannot load http://api.nestoria.co.uk/api?country=uk&pretty=1&action=search_listings&place_name=soho&encoding=json&listing_type=rent. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http:// localhost' is therefore not allowed access.
searchByPlaceName: function() {
var url = baseurl+'country=uk&pretty=1&action=search_listings&place_name=london'+encoding+type;
return $http.get(url);
}
It seems that api.nestoria.co.uk
does not allow CORS. It has to set the Access-Control-Allow-Origin
header itself -- you have no direct control over that.
However, you can use JSONP. That site allows it via the callback
query parameter.
$http.jsonp(baseurl+'country=uk&pretty=1&action=search_listings&place_name=london'
+encoding+type + "&callback=JSON_CALLBACK")
这篇关于跨域$ http请求AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!