【问题标题】:dojo cometd is never readydojo cometd 从未准备好
【发布时间】:2012-04-14 23:06:11
【问题描述】:

我正在尝试使用 Jetty、Dojo 和 maven 设置 Bayeux 服务器和客户端。

我的问题是道场似乎永远都没有准备好。 require 中的回调永远不会被调用。

这是 HTML 页面的代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
   <title></title>
   <script data-dojo-config="parseOnLoad:true" src="dojo/dojo.js.uncompressed.js"></script>
   <script type="text/javascript">

      function initFormListener( onNewForm ) {

         require(["dojox/cometd", "dojo/io/script", "dojox/cometd/callbackPollTransport", "dojo/domReady!" ],
                     function ( cometd, io, callback ) {
                        console.log(" entered CometD function ");

                        // Function that manages the connection status with the Bayeux server
                        var _connected = false;

                        var _metaConnect = function ( message ) {
                           if ( cometd.isDisconnected() ) {
                              _connected = false;
                              console.log( "disconnected from server " + message );
                              return;
                           }

                           var wasConnected = _connected;
                           _connected = message.successful === true;
                           if ( !wasConnected && _connected ) {
                              console.log( "connected to server " );
                           }
                           else if ( wasConnected && !_connected ) {
                              console.log( "connection broken from server " + message );
                           }
                        }

                        // Function invoked when first contacting the server and
                        // when the server has lost the state of this client
                        var _metaHandshake = function ( handshake ) {
                           if ( handshake.successful === true ) {
                              cometd.batch( function () {
                                 cometd.subscribe( '/newFormData', function ( message ) {
                                    console.log( "new data for form " + message.formId + " in formData " + message.formDataId );
                                 } );
                              } );
                           }
                        }

                        // Disconnect when the page unloads
                        dojo.addOnUnload( function () {
                           cometd.disconnect( true );
                        } );

                        var cometURL = location.protocol + "//" + location.host + "/VisionWeb/cometd";
                        cometd.configure( {
                           url:cometURL,
                           logLevel:'debug'
                        } );

                        cometd.addListener( '/meta/handshake', _metaHandshake );
                        cometd.addListener( '/meta/connect', _metaConnect );

                        cometd.handshake();
                     } );
      }

      initFormListener( function() {console.log("cometd success")});
   </script>
</head>
<body>
   just some content
</body>
</html>

dojo 不是不能在服务器上运行的。确实如此。我的应用是用 dojo 1.7.2 编写的

是否存在我不知道的已知问题或我做错了什么?

感谢您提供有关如何找出从未调用回调的原因的任何提示。

【问题讨论】:

  • 只是想提一下我使用 FireBug 并且它通常会指出什么时候丢失了,但这次我没有收到错误消息。在回调函数中设置断点时,它永远不会到达,并且文本“进入 CometD 函数”永远不会出现在控制台中
  • 我强烈暗示所有文件都存在。如果我删除 dojox/cometd/_base.js,我会在 FireBug 中收到一条错误消息。这是预期的。

标签: comet dojo cometd


【解决方案1】:

您正在尝试使用cometD

根据cometD的Reference Manual,需要将标准Dojo工具包的部分js文件替换为cometD的Primer下载中提供的文件。

使用 cometD 的文档,您将在合理的时间内启动和运行您的应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多