由于 CORS 错误,无法将 XAMPP 上的 AngularJs amp 运行 连接到 API
Cannot connect AngularJs app running on XAMP to API because of CORS error
我有一个 AngularJs 应用程序 运行,它适用于:https://jsonplaceholder.typicode.com/todos
但不能与另一个 API(无法显示 link)哪个 returns 错误:
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(或者有其他选择吗?)
我需要将 Access-Control-Allow-Origin: localhost
添加到我的其他服务器 API
header
我有一个 AngularJs 应用程序 运行,它适用于:https://jsonplaceholder.typicode.com/todos
但不能与另一个 API(无法显示 link)哪个 returns 错误:
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(或者有其他选择吗?)
我需要将 Access-Control-Allow-Origin: localhost
添加到我的其他服务器 API
header