【发布时间】:2016-03-05 05:27:14
【问题描述】:
我收到此错误。 XMLHttpRequest 无法加载 http://communityempowerment.org.pk/test-sample/api/get_category_index/。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问 Origin 'http://localhost:8100'。
我的代码是
.controller('MenuCtrl', function($http, $scope){
$scope.categories = [];
$http.get("http://communityempowerment.org.pk/test-sample/api/get_category_index/").then
(function(data){
$scope.categories = data.data;
console.log(data);
}, function(err){
console.log(err);
})
})
【问题讨论】:
-
不能对随机跨域资源做ajax请求,违反同源策略。唯一的解决方法是控制服务器并添加正确的标头,返回 JSONP,或使用您自己的服务器发出请求。
标签: javascript angularjs ionic-framework