XMLHttpRequest 跨域问题

在使用jquery的ajax请求的时候,出现了这么个问题。

XMLHttpRequest cannot load file:///some/path/some.html

Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

因为是本地测试,直接在chrome浏览器打开html页面,调用ajax请求时出现问题。后来在stackoverflow上找到类似的问题。XMLHttpRequest 跨域请求,因为安全的原因,浏览器默认禁用了这种请求方式,避免在浏览网页的时候,某些网站恶意使用ajax请求等方式访问系统文件。

 

解决方法:

1. 安装一个webserver,使用http://some/path/some.html的方式访问数据。

简单的python3 http server

 

python3 -m http.server PORT_NUM

2.chrome浏览器下,也可以使用这种方式。打开cmd,打开chrome.exe文件路径,输入chrome --allow-file-access-from-files

posted @ 2015-03-25 17:07  SEC.VIP_网络安全服务  阅读(130)  评论(0编辑  收藏  举报