websocket object is not initialized when using jquery cdn

182 Views Asked by At

I have written two files. Application.cfc

component output="false"{
 this.name = "WebSocket";
 this.wschannels = [{name:"news"}];
}

Index.cfm

<html>
<head>
    <script>
        function myfun(){
            myWSDemo.publish("news","This is a test message.");
        }

        function myfun1(){
            myWSDemo.subscribe("news");
        }

        var messageHandler = function(message) {
            console.log("Message Handler is called.");
            console.log(message);
            if(message.type == "data"){
                 var txt=document.getElementById("message"); 
                 txt.innerHTML+= message.data + "<br/>";
            }
        }   
    </script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" />
</head>
<body>
    <cfwebsocket name="myWSDemo" onmessage="messageHandler">    
    <input type="button" id="sub" onclick="myfun1()" value="Subscribe"/>
    <input type="button" id="pub" onclick="myfun()" value="Publish"/>
    <div id="message"></div>
</body>
</html>

This code is working perfectly when <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" /> is not included in the page.

When I am adding jquery cdn link it is not initializing the web-socket object. Any one having any idea about this issue?

0

There are 0 best solutions below