jquery.cometd 初始化问题

发布于 2024-12-28 03:53:41 字数 2075 浏览 2 评论 0原文

我正在尝试创建一个简单的测试 HTML 页面,该页面显示来自 Bayeux 服务器的消息。

这是代码:

  <html>
  <head>
     <title>test Baeyux connexion</title>
     <script type="text/javascript" src="jquery/jquery-1.6.2.js"></script>
     <script type="text/javascript" src="jquery/jquery.cometd.js"></script>
     <script type="text/javascript" src="jquery/json2.js"></script>
  </head>
  <body>
  <script type="text/javascript">
     jQuery( document ).ready( function ( $ ) {
        var cometd = $.cometd;

        cometd.init( 'http://localhost:8080/VisionWeb/cometd' );
        cometd.addListener( "/meta/handshake", function ( message ) {

        } );

        cometd.addListener( '/meta/connect', function ( message ) {
           // if (cometd.getStatus() === 'disconnecting' || cometd.getStatus() === 'disconnected')
           if ( cometd.isDisconnected() ) // Available since 1.1.2
           {
              return;
           }
           var wasConnected = _connected;
           _connected = message.successful;
           if ( !wasConnected && _connected ) {
              $( "#con" ).text( "RECONNECTED" );
           }
           else if ( wasConnected && !_connected ) {
              $( "#con" ).text( "DISCONNECTED" );
           } else if ( _connected ) {
              $( "#con" ).text( "ON" );
           } else {
              $( "#con" ).text( "OFF" );
           }
        } );

        cometd.addListener( '/meta/disconnect', function ( message ) {
           if ( message.successful ) {
              _connected = false;
           }
        } );
     });
  </script>
  <p>connexion is <span id="con">UNDEFINED</span></p>

  <p>comet messages</p>
  <ul id="msg"></ul>
  </body>
  </html>

当我尝试打开此页面时,出现以下 javascript 错误:组织未定义 在 jquery.cometd.js 第 20 行。有问题的行是:

org.cometd.JSON.toJSON = JSON.stringify;

这是我下载的一个库,我想我在这里做错了什么,但我不知道它是什么。

提前致谢, 米夏

I am trying to create a simple test HTML page which shows messages from a Bayeux server.

this is the code:

  <html>
  <head>
     <title>test Baeyux connexion</title>
     <script type="text/javascript" src="jquery/jquery-1.6.2.js"></script>
     <script type="text/javascript" src="jquery/jquery.cometd.js"></script>
     <script type="text/javascript" src="jquery/json2.js"></script>
  </head>
  <body>
  <script type="text/javascript">
     jQuery( document ).ready( function ( $ ) {
        var cometd = $.cometd;

        cometd.init( 'http://localhost:8080/VisionWeb/cometd' );
        cometd.addListener( "/meta/handshake", function ( message ) {

        } );

        cometd.addListener( '/meta/connect', function ( message ) {
           // if (cometd.getStatus() === 'disconnecting' || cometd.getStatus() === 'disconnected')
           if ( cometd.isDisconnected() ) // Available since 1.1.2
           {
              return;
           }
           var wasConnected = _connected;
           _connected = message.successful;
           if ( !wasConnected && _connected ) {
              $( "#con" ).text( "RECONNECTED" );
           }
           else if ( wasConnected && !_connected ) {
              $( "#con" ).text( "DISCONNECTED" );
           } else if ( _connected ) {
              $( "#con" ).text( "ON" );
           } else {
              $( "#con" ).text( "OFF" );
           }
        } );

        cometd.addListener( '/meta/disconnect', function ( message ) {
           if ( message.successful ) {
              _connected = false;
           }
        } );
     });
  </script>
  <p>connexion is <span id="con">UNDEFINED</span></p>

  <p>comet messages</p>
  <ul id="msg"></ul>
  </body>
  </html>

when I try to open this page I get the following javascript error: org is not defined
at line 20 of jquery.cometd.js. The line in question is:

org.cometd.JSON.toJSON = JSON.stringify;

this is a library I downloaded and I guess I am doing something wrong here but I have no clue as to what it is.

thanks in advance,
Micha

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来日方长 2025-01-04 03:53:41

您还没有包含 cometd javascript 库。这必须在包含 jquery.cometd.js 之前完成。 jquery.cometd.js 只是将 cometd 和 jquery 连接在一起的粘合剂。尝试像这样排序你的脚本:

    <script type="text/javascript" src="/org/cometd.js"></script>
    <script type="text/javascript" src="/org/cometd/ReloadExtension.js"></script>
    <script type="text/javascript" src="/jquery/jquery-1.6.4.js"></script>
    <script type="text/javascript" src="/jquery/json2.js"></script>
    <script type="text/javascript" src="/jquery/jquery.cookie.js"></script>
    <script type="text/javascript" src="/jquery/jquery.cometd.js"></script>
    <script type="text/javascript" src="/jquery/jquery.cometd-reload.js"></script>

You haven't included the cometd javascript library. This must be done before including jquery.cometd.js. jquery.cometd.js is just the glue that joins cometd and jquery together. Try ordering your scripts more like this:

    <script type="text/javascript" src="/org/cometd.js"></script>
    <script type="text/javascript" src="/org/cometd/ReloadExtension.js"></script>
    <script type="text/javascript" src="/jquery/jquery-1.6.4.js"></script>
    <script type="text/javascript" src="/jquery/json2.js"></script>
    <script type="text/javascript" src="/jquery/jquery.cookie.js"></script>
    <script type="text/javascript" src="/jquery/jquery.cometd.js"></script>
    <script type="text/javascript" src="/jquery/jquery.cometd-reload.js"></script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文