Reputation: 115
When a push is recieved I want it to update a div. I don't understand javascript that well, but this is what i've got so far.
#subscription
var pusher = new Pusher('<%= Pusher.key %>');
var channel = pusher.subscribe('test_channel');
channel.bind('greet', function(data) {
$("#data.greeting").load(location.href + " #data.greeting");
});
#trigger
<%= Pusher['test_channel'].trigger('greet', { :greeting => "present"}) %>
#present is the div im trying to update in this example. the trigger works, but nothing happens on the sub end
Upvotes: 1
Views: 83
Reputation: 115
I solved it like this.
channel.bind('greet', function(data) {
$("#present").load(location.href + " #present");
});
it just ignores the input from the trigger and runs that commands, works well. might be a little more work implementing in this way, but it will do.
Upvotes: 0
Reputation: 3351
Are you rendering the trigger in the view, as in, in your .erb
file?
Trying keeping the subscription code the same and then running the trigger code in your rails console, as in, just this bit:
Pusher['test_channel'].trigger('greet', { :greeting => "present"})
Upvotes: 1