我目前正在试验 Google App Engine/Go + Polymer.dart 网站 http://xclamm.appspot.com/ .
问题是当我访问 http://xclamm.appspot.com/ 时出现以下错误使用 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.
我做了一些研究,发现问题与我如何引用 /_ah/channel/jsapi
有关,但我找不到解决方法。我尝试了以下方式来引用channel.js,但我仍然得到同样的错误。
<!-- 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>
如果我在 dev_appserver.py 上运行该网站,它似乎工作正常。我错过了什么吗?
源代码位于https://github.com/rillomas/xclamm-gae。 ,并且我正在使用适用于 Go (x64 Windows) 的 Google App Engine SDK 1.8.4。
最佳答案
我移动了 <script type="text/javascript" src="/_ah/channel/jsapi"></script>
来自 main-stage.html
的标签(内部 Web 组件的 html)到 index.html
(网站的根 html),CORS 错误消失了。
<script>
标签最初放置在 <polymer-element>
中标记,并且(可能)被 Polymer.dart 转换为 XMLHttpRequest,导致错误。
关于google-app-engine - 获取 Channel API 客户端脚本时出现 CORS 相关错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18851398/