Ajax本地跨域问题 Cross origin requests are only supported for HTTP

Posted AmilyAmily

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ajax本地跨域问题 Cross origin requests are only supported for HTTP相关的知识,希望对你有一定的参考价值。

问题:打开本地html文件时,报错如下

Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-resource.
 
分析:浏览器为了安全性考虑,默认对跨域访问禁止。
 
解决:给浏览器传入启动参数(allow-file-access-from-files),允许跨域访问。
Windows下,运行(CMD+R)或建立快捷方式:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files
 
用这个方法必须关闭谷歌浏览器再执行才有效

以上是关于Ajax本地跨域问题 Cross origin requests are only supported for HTTP的主要内容,如果未能解决你的问题,请参考以下文章

跨域资源共享(Cross-Origin Resource Sharing)

Ajax跨域设置Access-Control-Allow-Origin

(转)跨域的另一种解决方案——CORS(Cross-Origin Resource Sharing)跨域资源共享

本地数据访问时出现跨域问题Cross origin requests are only supported for protocol schemes: ……

Cross origin requests are only supported for HTTP

Ajax - 跨域请求被阻止 - 'Access-Control-Allow-Origin' 缺失 - Spring Boot