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

查看:248
本文介绍了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
exclude-result-prefixes = yweather
xmlns:yweather =http://xml.weather.yahoo.com/ns/rss/1.0xmlns:geo =http://www.w3.org/2003/01/geo/ wgs​​84_pos#>
< xsl:output omit-xml-declaration =yesindent =yes/>

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

我想将html输出加载到html文件的div中,我试图如下所示使用jQuery:

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

但是我收到以下错误:
Origin-null不被Access-Control -Allow-Origin。



我已经阅读了关于向xslt添加头文件的信息,但我不知道如何去做,所以任何帮助将不胜感激,并且如果在html输出中加载不能这样完成,那么如何做到这一点的建议会很好。

解决方案

p> Origin null 是本地文件系统,所以这表明您正在加载执行 load 的HTML页面>通过 file:/// URL调用(例如,只需在本地文件浏览器或类似文件中双击它)。不同的浏览器采用不同的方法将同源策略应用于本地文件。



我的猜测是,您正在使用Chrome浏览器看到这一点。 Chrome将SOP应用于本地文件的规则非常严格,它甚至不允许从与文档相同的目录加载文件。 Opera也是如此。其他一些浏览器(如Firefox)允许对本地文件进行有限的访问。但基本上,在本地资源中使用ajax不会跨浏览器工作。



如果您只是在本地测试一些您将真正部署到而不是使用本地文件,而是安装一个简单的Web服务器,并通过 http:// URL来测试。这给你一个更准确的安全图片。


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). Different browsers take different approaches to applying the Same Origin Policy to local files.

My guess is that you're seeing this using Chrome. Chrome's rules for applying the SOP to local files are very tight, it disallows even loading files from the same directory as the document. So does Opera. Some other browsers, such as Firefox, allow limited access to local files. But basically, using ajax with local resources isn't going to work cross-browser.

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.

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

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