我收到此错误。 XMLHttpRequest无法加载http://communityempowerment.org.pk/test-sample/api/get_category_index/。请求的资源上没有“Access-Control-Allow-Origin”标题。因此不允许访问原产地'http://localhost:8100'。XMLHttpRequest无法加载http否访问控制 - 允许源标头angularjs
我的代码是
.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或使用您自己的服务器发出请求。 – adeneo