我在Chrome扩展程序中使用了Channel API。为什么Google App Engine通道API(jsapi)无法加载Chrome扩展程序?
在Google App Engine Channel API Javascript Reference (Python)页它说,
Include the following in your html page before any JavaScript code that refers to it:
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
于是,我把在我options.html文件的标题:
<html>
<head>
<title>Extension Options</title>
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
</head>
而Chrome抛出jsapiFailed to load resource
错误。我究竟做错了什么?
更新
按Moishe的回答我更新调用JSAPI这样的:
<head>
<title>Extension Options</title>
<!-- this does not work because it is local
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
-->
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
</head>
更新
我加入onopen
等性能。现在我收到onopen
提醒,但我没有收到evt.data
提醒。我究竟做错了什么?
<html>
<head>
<title>Extension Options</title>
<!-- this does not work because it is local url
<script type="text/javascript" src="/_ah/channel/jsapi"></script>
-->
<script type="text/javascript" src="https://talkgadget.google.com/talkgadget/channel.js"></script>
</head>
<body>
<p>Enter your gmail address:</p>
<textarea id="getEmail" style="margin-bottom: 4px; width: 250px; height: 20px">
</textarea><br />
<button id="save">Save</button>
<!--<button id="save">Clear</button>-->
<script>
document.getElementById("getEmail").placeholder = "your gmail address" ;
//save entered gmail address
document.getElementById("save").addEventListener
(
"click",
function()
{
var userEmail = document.getElementById("getEmail").value;
var formData = new FormData();
formData.append("extension_user", userEmail);
alert("after formData.append")
var channel;
var socket;
var handler =
{
onopen: function() { alert("onopen") },
onerror: function() { alert("onerror") },
onclose: function() { alert("onclose") },
onmessage:
function (evt)
{
//evt.data will be what the server sends in channel.send_message
console.log("evt.data received from authhandler: " + evt.data);
alert("evt.data is: " + evt.data)
}
};
var xhr = new XMLHttpRequest();
//changed to lowercase
xhr.onreadystatechange = function()
{
//alert("xhr.onReadyStateChange")
//error handling etc not included
if (xhr.readyState == 4 && xhr.status == 200)
{
token = xhr.responseText;
alert("token: " + token)
channel = new goog.appengine.Channel(token);
socket = channel.open(handler);
}
};
xhr.open("POST", "http://ting-1.appspot.com/authsender", true);
xhr.send(formData);
console.log("formData sent to authsender: " + formData);
}, false
)
</script>
</body>
</html>
这是使用dev_appserver还是在生产中?您能否提供Chrome开发工具中“网络”选项卡的任何详细信息? –
这是生产中。首先,“网络”标签中没有任何内容;然后按指示重新加载页面,我看到2个项目:options.html和jsapi:name:options.html;方法:GET;状态:(来自缓存);类型:text/html的;大小:(从缓存中);时间:3ms和'jsapi/_ah/channel; GET,(失败);不确定的; 30B; 5ms'谢谢! – Zeynel
你介意告诉我你的appid吗?如果您尝试直接导航至“http://your-app-id.appspot.com/_ah/channel/jsapi”,会发生什么情况? –