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

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -