为什么当我使用 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">
跨域共享标准不包括img
标签,但 XHR/fetch 请求和某些情况(包括将图像绘制到画布)会这样做。
欲了解更多信息:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#What_requests_use_CORS https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#What_requests_use_CORS
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)