XMLHttpRequest 跨域问题

来源:互联网 发布:java list<>遍历 编辑:程序博客网 时间:2024/05/23 14:20

在使用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的方式访问数据。


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


0 0
原创粉丝点击