javascript - Query regarding adding PubNub Channel dynamically -


i using pubnub publish , subscribe messages. there technical requirement in have add pubnub channel name dynamically. problem is, cannot load page again. work doing through jquery , interacting server using ajax.

is possible so. if yes, how.

best, abhinav sharma

yes possible. first initialize pubnub using pubnub.init() method if don't use div setup credentials. can make ajax request server obtain channel name. after obtaining channel name, subscribe via pubnub subscribe() call. can subscribe pubnub channel @ time.

assuming server respond request text datatype:

var pubnub = pubnub.init({'publish_key':'demo','subscribe_key':'demo'}); pubnub.ready(); $.ajax({     url :'http://example.com/getchannel',     type :'get',     datatype :'text',     success : function(data) {         pubnub.subscribe({             channel : data,             message : function(m) { console.log('new message received: ',m);         });     }         }); 

Comments

Popular posts from this blog

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -