Access-Control-Allow-Origin 不允许 Origin null [英] Origin null is not allowed by Access-Control-Allow-Origin

查看:65
本文介绍了Access-Control-Allow-Origin 不允许 Origin null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个小的 xslt 文件来创建一个名为 weather.xsl 的 html 输出,代码如下:

<!-- DWXMLSource="http://weather.yahooapis.com/forecastrss?w=38325&u=c" --><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"排除结果前缀=yweather"xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"><xsl:output omit-xml-declaration="yes" indent="yes"/><xsl:strip-space elements="*"/><xsl:template match="/"><img src="{/*/*/item/yweather:condition/@text}.jpg"/></xsl:模板></xsl:stylesheet>

我想将 html 输出加载到 html 文件中的 div 中,我正在尝试使用 jQuery 执行如下操作:

<script type="text/javascript">$('#result').load('weather.xsl');

但我收到以下错误:Access-Control-Allow-Origin 不允许 Origin null.

我已经阅读了有关向 xslt 添加标题的内容,但我不确定如何执行此操作,因此将不胜感激,如果无法以这种方式加载 html 输出,请提出建议关于如何做到这一点会很棒.

解决方案

Origin null 是本地文件系统,因此这表明您正在加载执行 load 的 HTML 页面 通过 file:/// URL 调用(例如,只需在本地文件浏览器或类似工具中双击它).

大多数浏览器将同源政策应用于本地文件,甚至禁止从与文档相同的目录.(以前是 Firefox 允许相同的目录和子目录,但是 不再是.

基本上,将 ajax 与本地资源一起使用是行不通的.

如果您只是在本地测试将真正部署到网络的内容,而不是使用本地文件,请安装一个简单的网络服务器并通过 http:// URL 进行测试.这为您提供了更准确的安全图片.您的 IDE 可能内置了某种服务器(直接或通过扩展),让您只需点击运行"即可.在 IDE 中启动服务器并提供文件.

I have made a small xslt file to create an html output called weather.xsl with code as follows:

<!-- DWXMLSource="http://weather.yahooapis.com/forecastrss?w=38325&u=c" -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="yweather"
xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
    <img src="{/*/*/item/yweather:condition/@text}.jpg"/>
</xsl:template>
</xsl:stylesheet>

I want to load in the html output into a div in an html file which I'm trying to do using jQuery as follows:

<div id="result">
<script type="text/javascript">
$('#result').load('weather.xsl');
</script>
</div>

But I am getting the following error: Origin null is not allowed by Access-Control-Allow-Origin.

I've read about adding a header to the xslt, but I'm not sure how to do that, so any help would be appreciated, and if loading in the html ouput can't be done this way, then advice on how else to do it would be great.

解决方案

Origin null is the local file system, so that suggests that you're loading the HTML page that does the load call via a file:/// URL (e.g., just double-clicking it in a local file browser or similar).

Most browsers apply the Same Origin Policy to local files by disallowing even loading files from the same directory as the document. (It used to be that Firefox allowed the same directory and subdirectories, but not any longer.

Basically, using ajax with local resources doesn't work.

If you're just testing something locally that you'll really be deploying to the web, rather than use local files, install a simple web server and test via http:// URLs instead. That gives you a much more accurate security picture. Your IDE may well have some kind of server built in (directly or via an extension) that lets you just hit "run" in the IDE and have the server fired up and serving the file.

这篇关于Access-Control-Allow-Origin 不允许 Origin null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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