获取Channel API客户端脚本时出现的CORS相关错误

huangapple go评论89阅读模式
英文:

CORS related errors when getting Channel API client script

问题

我目前正在使用Google App Engine/Go + Polymer.dart构建一个网站,网址是http://xclamm.appspot.com/。

问题是,当我使用Dartium(版本号为31.0.1612.0 Developer Build 219647)访问http://xclamm.appspot.com/时,出现以下错误:

XMLHttpRequest无法加载https://talkgadget.google.com/talkgadget/channel.js。请求的资源上没有'Access-Control-Allow-Origin'头部,因此不允许从源' http://xclamm.appspot.com'访问。

我进行了一些研究,发现问题与我如何引用/_ah/channel/jsapi有关,但我找不到解决方法。我尝试了以下几种引用channel.js的方式,但仍然出现相同的错误。

<!-- 以下方式都不起作用 -->
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
<!-- 以下方式也不起作用 -->
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>

如果我在dev_appserver.py上运行网站,似乎一切正常。我是否漏掉了什么?

源代码可在https://github.com/rillomas/xclamm-gae找到,我正在使用Google App Engine SDK 1.8.4 for Go(x64 Windows)。

英文:

I'm currently experimenting with a Google App Engine/Go + Polymer.dart website at http://xclamm.appspot.com/.

The problem is that I get the following error when I access http://xclamm.appspot.com/ with Dartium (31.0.1612.0 Developer Build 219647).

XMLHttpRequest cannot load https://talkgadget.google.com/talkgadget/channel.js. No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource. Origin &#39;http://xclamm.appspot.com&#39; is therefore not allowed access. 

I did some research and found that the problem is related with how I refer to /_ah/channel/jsapi, but I can't find how to fix it. I tried the following ways to refer to channel.js, but I still get the same error.

&lt;!-- Following doesn&#39;t work --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/_ah/channel/jsapi&quot;&gt;&lt;/script&gt;
&lt;!-- Following doesn&#39;t work either --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://talkgadget.google.com/talkgadget/channel.js&quot;&gt;&lt;/script&gt;

If I run the website on dev_appserver.py, it seems to be working OK. Am I missing something?

The source code is available at https://github.com/rillomas/xclamm-gae, and I'm using Google App Engine SDK 1.8.4 for Go (x64 Windows).

答案1

得分: 1

我将<script type="text/javascript" src="/_ah/channel/jsapi"></script>标签从main-stage.html(内部网页组件的HTML)移动到index.html(网站的根HTML),然后CORS错误消失了。

最初,<script>标签被放置在一个<polymer-element>标签内,然后(可能)由Polymer.dart转换为XMLHttpRequest,导致了这个错误。

英文:

I moved the &lt;script type=&quot;text/javascript&quot; src=&quot;/_ah/channel/jsapi&quot;&gt;&lt;/script&gt; tag from main-stage.html (html for an internal web component) to index.html (root html for the website), and the CORS error went away.

The &lt;script&gt; tag was originally placed inside a &lt;polymer-element&gt; tag, and was (probably) translated to an XMLHttpRequest by Polymer.dart, causing the error.

huangapple
  • 本文由 发表于 2013年9月17日 21:35:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/18851398.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定