允许Google Chrome使用XMLHttpRequest从本地文件加载URL
当尝试从本地文件使用XMLHttpRequest执行HTTP请求时,基本上由于Access-Control-Allow-Origin违例而失败。 
但是,我自己使用本地网页,所以我想知道是否有任何方法让Google Chrome允许这些请求,这些请求是从本地文件到Internet上的URL。
 例如, $.get('http://www.google.com/')在本地文件中执行失败,但是我自己编写了这个页面,而且我自己使用了它,所以它会非常有用我可以压制它并加载URL。 
那么,我怎样才能允许谷歌浏览器使用本地文件中的XMLHttpRequest加载URL呢?
 启动铬与--disable-web-security 
在Windows上:
 chrome.exe --disable-web-security 
在Mac上:
 open /Applications/Google\ Chrome.app/ --args --disable-web-security 
 这将允许跨域请求。 
 我不知道这是否也适用于本地文件,但让我们知道! 
并提到,这正是你所期望的,它禁用了网络安全,所以要小心。
 使用--disable-web-security开关是相当危险的 ! 为什么禁用安全性,只要允许XMLHttpRequest使用--allow-file-access-from-files开关来访问其他文件中--allow-file-access-from-files ? 
在使用这些命令之前,请务必结束所有正在运行的Chrome实例。
在Windows上:
 chrome.exe --allow-file-access-from-files 
在Mac上:
 open /Applications/Google\ Chrome.app/ --args --allow-file-access-from-files 
Chrome的这个“功能”讨论:
Mac版本。 从终端运行:
 open /Applications/Google\ Chrome.app/ --args --allow-file-access-from-files 
在Ubuntu上:
 chromium-browser --disable-web-security 
有关更多详情/开关:
http://peter.sh/experiments/chromium-command-line-switches/
参考