jquery.cometd initialization problems

2.5k views Asked by At

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

1

There are 1 answers

0
Heathen On BEST ANSWER

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>