天天看点

jQuery.ajax在谷歌浏览器下访问本地文件问题 XMLHttpRequest Origin null is not allowed Access-Control-Access-Allow for file:/// to file:/// (Serverless)

返回错误,打开控制台,发现提示信息:

XMLHttpRequest cannot load file:///home/lzh/%E6%96%87%E6%A1%A3/ajax/jquery/jquery.joytech/J/cities.xml. Origin null is not allowed by Access-Control-Allow-Origin.

http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-access-allow-for-file

XMLHttpRequest Origin null is not allowed Access-Control-Access-Allow for file:/// to file:/// (Serverless)

For instances where running a local webserver is not an option, you can allow Chrome access to 

file://

 files via a browser switch. After some digging, I found this discussion, which mentions a browser switch in opening post. Run your Chrome instance with:

chrome.exe --allow-file-access-from-files

           

This may be acceptable for development environments, but little else. You certainly don't want this on all the time. This still appears to be an open issue (as of Jan 2011).

See also: Problems with jQuery getJSON using local files in Chrome

继续阅读