【发布时间】:2013-07-10 00:31:25
【问题描述】:
我有一个使用 GAE 频道 API 的简单完整应用程序。它可以在我的本地机器上运行,但是当我将它上传到 apppot 时,通道 api 应该是的 url 似乎是空的,并且应用程序失败并显示消息“goog is not found”。
服务器:
import webapp2
import jinja2
import os
import time
import logging
channel_key = 'key'
class MainHandler(webapp2.RequestHandler):
def get(self):
token = channel.create_channel("1")
template_values = {'token': token}
template = env.get_template('index.html')
self.response.write(template.render(template_values))
class OpenedHandler(webapp2.RequestHandler):
def post(self):
channel.send_message("1", "hi")
logging.info("send hi");
env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
app = webapp2.WSGIApplication([
('/', MainHandler),
('/opened', OpenedHandler)
], debug=True)
客户:
<!DOCTYPE html>
<html>
<body>
<div id="debug">_</div>
<!--
<script src="https://talkgadget.google.com/talkgadget/channel.js"></script>
<script type="text/javascript" src="/static/channel.js"></script>
-->
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
<script>
function debug(s) {
document.getElementById("debug").innerHTML = s;
}
my_func = function() {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/opened');
xhr.send();
}
onOpened = function() {
debug("open");
setTimeout(my_func, 2000);
};
onMessage = function(message) {
alert("something recieved");
alert(message);
}
channel = new goog.appengine.Channel("{{token}}") // this is where it fails
socket = channel.open();
socket.onopen = onOpened;
socket.onmessage = onMessage;
socket.onerror = function(e){
alert("error:"+e['description']);
};
socket.onclose = function(){
alert("close");
};
</script>
</body>
</html>
在我的本地机器上,调用 onOpened 函数并发送消息。在 apppot 上安装时,我得到了
"Uncaught ReferenceError: goog is not defined"
紧接着
channel = new goog.appengine.Channel("{{token}}")
当我查看开发工具窗口的资源选项卡并单击“jsapi”时,它似乎是空的:
(来源:crb at www.sonic.net)
我尝试过其他的 url,你可以看到这些在 html 中被注释掉了,但是没有任何效果。我很确定这是正确的,我无法解释为什么 api 似乎是空的,因此没有定义“goog”。
感谢您的任何建议。
【问题讨论】:
-
Grrr。我刚刚注意到这在 Safari 上运行良好,谷歌今天或昨天自动将我的 Chrome 更新到了新版本。所以我认为这是 Chrome 的问题。
-
尝试刷新缓存。
-
感谢您的想法。我确实清除了缓存。结果相同。
-
也可以在 Firefox 中使用。只是不是 Chrome。
标签: google-app-engine channel-api