英文:
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 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xclamm.appspot.com' 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.
<!-- Following doesn't work -->
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
<!-- Following doesn't work either -->
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
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 <script type="text/javascript" src="/_ah/channel/jsapi"></script>
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 <script>
tag was originally placed inside a <polymer-element>
tag, and was (probably) translated to an XMLHttpRequest by Polymer.dart, causing the error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论