我收到此错误。 XMLHttpRequest 无法加载 http://communityempowerment.org.pk/test-sample/api/get_category_index/ 。请求的资源上不存在“Access-Control-Allow-Origin” header 。来源'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);
})
})
最佳答案
提供http://communityempowerment.org.pk/test-sample/api/get_category_index/
服务的服务器不允许跨源请求。看看CORS on MDN 。如果您控制服务器,则可以将 header Access-Control-Allow-Origin
更改为一组特定的域或通配符 *
以允许来自所有来源的访问.
关于javascript - XMLHttpRequest 无法加载 http 无 Access-Control-Allow-Origin header angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35810446/