今天我尝试从带有 ColdFusion 10 的 Web-socket 中的“Hello World”程序开始。我从 adobe 论坛中给出的示例开始。
应用程序.cfc
<cfcomponent output="false">
<cfscript>
this.name = "helloworld";
this.wschannels = [{name="world"}];
</cfscript>
</cfcomponent>
索引.cfm
<cfwebsocket name="myworld" onMessage="msgHandler" subscribeto="world" onOpen="openHandler"/>
<script>
var msgHandler = function(message) {
// Get data from the recieved message token
console.log(message);
var data = message.data;
if(data) {
// If data is present write it to the div
var txt=document.getElementById("myDiv");
txt.innerHTML+= data + "<br>";
}
}
var sayHello = function() {
// Client says Hello World
myworld.publish("world","Hello World! WebSocket is here !!"); }
var openHandler = function() {
// do nothing
}
</script>
<input id="hello" type="button" value="Say Hello!" onclick="sayHello();">
<div id="myDiv"></div>
但它不起作用。错误截图:
请帮忙。