XMLHttpRequest Origin null is not allowed access-Control-Allow-Origin for file:///to file:///(Serverless) [英] XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless)
问题描述
我正在尝试创建一个可以通过启动索引文件在本地下载和运行的网站.
I'm trying to create a website that can be downloaded and run locally by launching its index file.
所有文件都是本地的,没有使用在线资源.
All the files are local, no resources are used online.
当我尝试使用 jQuery 的 AJAXSLT 插件处理带有 XSL 模板的 XML 文件(在子目录中)时,我收到以下错误:
When I try to use the AJAXSLT plugin for jQuery to process an XML file with an XSL template (in sub directories), I receive the following errors:
XMLHttpRequest 无法加载 file:///C:/path/to/XSL%20Website/data/home.xml.Access-Control-Allow-Origin 不允许 Origin null.
XMLHttpRequest 无法加载 file:///C:/path/to/XSL%20Website/assets/xsl/main.xsl.Access-Control-Allow-Origin 不允许 Origin null.
发出请求的索引文件是 file:///C:/path/to/XSL%20Website/index.html
而使用的 JavaScript 文件存储在 file:///C:/path/to/XSL%20Website/assets/js/
.
The index file making the request is file:///C:/path/to/XSL%20Website/index.html
while the JavaScript files used are stored in file:///C:/path/to/XSL%20Website/assets/js/
.
我该如何解决这个问题?
How can I do to fix this issue?
推荐答案
对于无法选择运行本地网络服务器的情况,您可以允许 Chrome 通过浏览器访问 file://
文件转变.经过一番挖掘,我发现了这个讨论,其中提到了浏览器切换开帖.运行您的 Chrome 实例:
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
这对于开发环境来说可能是可以接受的,但除此之外别无他法.您当然不希望一直这样.这似乎仍然是一个悬而未决的问题(截至 2011 年 1 月).
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).
另见:使用 jQuery getJSON 的问题Chrome 中的本地文件
这篇关于XMLHttpRequest Origin null is not allowed access-Control-Allow-Origin for file:///to file:///(Serverless)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!