从源“http://localhost:8080”访问“API_URL”的 XMLHttpRequest 已被 CORS 策略阻止:

sel*_*mar 12 typescript ionic3 angular

Access to XMLHttpRequest at 'API_URL' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

当我运行我的本地主机系统来访问服务器 API 时。它将生成令牌而不是我收到类似上述错误的错误。请帮我。

小智 0

您需要在 API 中启用跨域资源,以便可以作为调用者从本地主机访问它。

更多信息请点击此处https://enable-cors.org/server.html和此处https://www.html5rocks.com/en/tutorials/cors/