gpt4 book ai didi

javascript - 使用 Pusher 库从 JS Web 客户端发送数据时生成异常

转载 作者:行者123 更新时间:2023-11-28 01:36:54 25 4
gpt4 key购买 nike

我是 Pusher 新手,目前在尝试从简单的 JS Web 客户端发送数据时遇到错误,我试图弄清楚这是代码错误还是浏览器问题(我怀疑是浏览器问题)。所发生的情况是,我使用一个简单的 Perl 脚本通过 Pusher 服务向在 FireFox 23.0.1 中运行的 Web 客户端发送一条文本消息。消息被正确接收(是的!),但是当我尝试发送返回消息时,我在“pusher.min.js(第 65 行)”处收到“未捕获的异常:[object Object]”错误,其中显示了 Pusher 库代码它试图创建一个 Flash 对象...

uncaught exception: [object Object]
...try{return Boolean(new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))}catch(a){...

该代码与 Pusher 站点中的许多 JS 演示略有不同...

<!DOCTYPE html>
<head>
<title>Pusher Test</title>
<script src="http://js.pusher.com/2.1/pusher.min.js" type="text/javascript"></script>
<script type="text/javascript">
// Enable pusher logging - don't include this in production
Pusher.log = function(message) {
if (window.console && window.console.log) {
window.console.log(message);
} //end if
}; //end function

var channelName='test_channel';
var eventName='status_update';

var pusher = new Pusher( [AppID removed] );
var channel = pusher.subscribe(channelName);
var callback = function(data) {
// add comment into page
alert(data);
console.log(data);
var triggered = channel.trigger(channelName, {data:"hello yourself"});
}; //end callback

pusher.bind(eventName, callback);
</script>
</head>

Flash(版本 11.8.800.168)已安装并启用。

代码正确还是我做了一些愚蠢的事情?如果代码正确,有人知道我如何解决这个问题吗?

最佳答案

只需将 status_update 更改为 client-status_update 即可。

Client events must be prefixed by client-. Events with any other prefix will be rejected by the Pusher server, as will events sent to channels to which the client is not subscribed.

http://pusher.com/docs/client_api_guide/client_events

关于javascript - 使用 Pusher 库从 JS Web 客户端发送数据时生成异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21438089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com