1
有人可以帮助我阅读示例回调中返回的推送器消息。我直接从他们的网站上看到了这个例子,但是警告框只是说'未定义',但是console.log输出一切正常。我通过帐户控制面板中的API控制台发送测试消息。我正在改变关键和通道,下面的代码是为了stackoverflow的好处。阅读推送器数据
<!DOCTYPE html>
<head>
<title>Pusher Test</title>
<script src="//js.pusher.com/2.2/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.log = function(message) {
if (window.console && window.console.log) {
window.console.log(message);
}
};
var pusher = new Pusher('MYAPIKEY');
var channel = pusher.subscribe('test_channel');
channel.bind('my_event', function(data) {
alert(data.message);
});
</script>
</head>
我试过data[0].message
和data.data
它总是返回undefined。如果我提醒data
,那么它会按预期返回[object] [object]
,所以有些东西我无法显示。
完美,谢谢!我是以JSON格式发送的,但没有一个叫做'message'的密钥 - 那就做到了! – Rob