duanshan3065
duanshan3065
2013-09-17 13:35
浏览 69
已采纳

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

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条回答 默认 最新

  • dsklfsdlkf1232
    dsklfsdlkf1232 2013-09-18 13:25
    已采纳

    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.

    点赞 评论

相关推荐