天天看點

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

繼續閱讀