我正在运行AngularJs应用程序,该应用程序可以与https://jsonplaceholder.typicode.com/todos
一起使用但不能使用其他API(无法显示链接)来返回错误:
Access to XMLHttpRequest at 'APIURL' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
21:35:47.396 angular.js:12410 Cross-Origin Read Blocking (CORB) blocked cross-origin response APIURL. See https://www.chromestatus.com/feature/5629709824032768 for more details.
工厂
factory.readProducts = function(){
return $http({
method: 'GET',
url: 'APIURL'
});
console.log('Factory read',factory.readProducts)
};
我查看了多个来源,但无法得出如何解决此错误的结论。我正在使用XAMPP在本地运行我的应用程序(或者有替代方法吗?)
答案 0 :(得分:0)
我需要将Access-Control-Allow-Origin: localhost
添加到其他服务器的API
标头中