Skip to content Skip to sidebar Skip to footer

Cant Publish Via PUBNUB. Origin Is Not Allowed By Access-Control-Allow-Origin

Make it Using javascript API. On their site works fine, but locally cant send cross-domain request. Where is the problem? request is XMLHttpRequest cannot load http://pubsub.pubn

Solution 1:

Using PubNub Everywhere! Even localhost and file:///

Using PubNub on localhost is super easy! You can even use PubNub on file:/// as well.

NOTE: always use a fixed versioned CDN in production, but pubnub-dev.js cdn is always the latest version, unminified.

<script src=https://cdn.pubnub.com/pubnub-dev.js></script>
<script>(function(){

    var pubnub = PUBNUB({
        // use your own pub/sub keys - demo keys are throttled
        publish_key   : 'demo',
        subscribe_key : 'demo',
        origin        : 'pubsub.pubnub.com',
        ssl           : true
    });

    pubnub.subscribe({
        channel  : 'my_channel',
        connect  : function() { /* ... CONNECTION SUCCESS ... */ },
        callback : function(message) {
            alert(message);
        }
    });

})();</script>

Remember to keep the origin set to pubsub.pubnub.com for all settings.


Post a Comment for "Cant Publish Via PUBNUB. Origin Is Not Allowed By Access-Control-Allow-Origin"