2012-03-08 41 views
1

我试图用彗星道场和它的例子有没有定义DojoX中没有定义

DojoX中的消息

我必须错过了一些东西明显

第一线失败

这是页(误差是在所述主体的第一行):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
      "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <title></title> 
    <script src="dojo/dojo.js" 
      data-dojo-config="async:true, parseOnLoad:true"> 
    </script> 
    <script> 
     require(["dojox/socket"]); 
    </script> 
</head> 
<body> 
<script type="text/javascript"> 
    var socket = dojox.socket("/cometd"); 
    function send(data) { 
     return socket.send(dojo.toJson(data)); 
    } 
    socket.on("connect", function() { 
     // send a handshake 
     send([ 
     { 
      "channel":"/meta/handshake", 
      "version":"1.0", 
      "minimumVersion":"1.0beta", 
      "supportedConnectionTypes":["long-polling"] // or ["callback-polling"] for x-domain 
     } 
     ]) 
     socket.on("message", function (data) { 
     // wait for the response so we can connect with the provided client id 
     data = dojo.fromJson(data); 
     if (data.error) { 
      throw new Error(error); 
     } 
     // get the client id for all future messages 
     clientId = data.clientId; 
     // send a connect message 
     send([ 
      { 
       "channel":"/meta/connect", 
       "clientId":clientId, 
       "connectionType":"long-polling" 
      }, 
      { // also send a subscription message 
       "channel":"/meta/subscribe", 
       "clientId":clientId, 
       "subscription":"/foo/**" 
      } 
     ]); 
     socket.on("message", function (data) { 
      alert("message from server " + data) 
     }); 
     }); 
    }); 
</script> 
</body> 
</html> 
+0

你想使用彗星?您是否按照cometD文档中的描述替换了相关的dojo文件? – perissf 2012-03-08 08:33:53

回答

1

您正在混合使用AMD和旧式模块语法。全新的AMD风格,require不是为您的命名空间创建一个全局变量,就像旧的dojo.require一样。

要么重写代码以充分使用新的AMD风格,要么删除在加载dojo时添加的async=true标志,以重新启用对旧模块样式的支持。

无论如何,它不应该是很难改写这个在AMD的风格...

require([ 
    'dojo/_base/json', //_base is for things that used to be in the root dojo namespace. 
    'dojox/socket' 
],function(
    json, 
    dojox_socket 
){ 
    var socket = dojox_socket("/cometd"); 
    function send(data) { 
     return socket.send(json.toJson(data)); 
    } 
    // and so on... 
}); 

(顺便说一句,你也可以,如果你在不使用任何声明部件去掉“parseOnLoad”标志的原始HTML)