一、问题
代码中通过url请求了来自服务器的数据:
return this.http.get(this.heroesUrl);
浏览器console报错:
Failed to load http://www.u0626.xyz/fileserver/heroes.json:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:4200' is therefore not allowed access.
HttpErrorResponse
"Http failure response for (unknown url): 0 Unknown Error"
二、跨域访问
访问非本域名下的资源
- 浏览器限制从脚本发起的跨域资源请求
- 浏览器拦截来自跨域请求的资源
三、解决方案
google chrome 插件 CORS Toggle
网友评论