美文网首页
CORS Toggle 浏览器跨域访问问题的解决

CORS Toggle 浏览器跨域访问问题的解决

作者: 哪种生活可以永远很轻松 | 来源:发表于2018-05-15 15:33 被阅读72次

一、问题

代码中通过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

相关文章

网友评论

      本文标题:CORS Toggle 浏览器跨域访问问题的解决

      本文链接:https://www.haomeiwen.com/subject/zotydftx.html