【发布时间】:2018-06-07 06:38:13
【问题描述】:
为什么,当我使用 fetch 从禁用响应 CORS 标头的服务器加载数据时,我预计会收到错误:Failed to load http://www.imgworlds.com/wp-content/uploads/2015/12/18-CONTACTUS-HEADER.jpg: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63343' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
但是会显示来自 img 标签的图像
<script>
fetch('http://www.imgworlds.com/wp-content/uploads/2015/12/18-CONTACTUS-HEADER.jpg').then(console.log);
</script>
<img src="http://www.imgworlds.com/wp-content/uploads/2015/12/18-CONTACTUS-HEADER.jpg">
【问题讨论】:
标签: html http http-headers cors