XMLHttpRequest原点null不允许file:///到file:///的Access-Control-Allow-Origin(无服务器) [英] XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless)

查看:95
本文介绍了XMLHttpRequest原点null不允许file:///到file:///的Access-Control-Allow-Origin(无服务器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个网站,可以通过启动其索引文件来下载并在本地运行.

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 cannot load file:///C:/path/to/XSL%20Website/data/home.xml. Origin null is not allowed by Access-Control-Allow-Origin.

XMLHttpRequest cannot load file:///C:/path/to/XSL%20Website/assets/xsl/main.xsl. Origin null is not allowed by Access-Control-Allow-Origin.

发出请求的索引文件为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/.

如何解决此问题?

推荐答案

对于不允许运行本地网络服务器的情况,您可以允许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原点null不允许file:///到file:///的Access-Control-Allow-Origin(无服务器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆