我正在尝试创建一个简单的测试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错误:org没有定义在jquery.cometd.js的第20行。有问题的行是:
org.cometd.JSON.toJSON = JSON.stringify;
这是我下载的一个库,我想我在这里做错了什么,但我不知道它是什么。
提前感谢,Micha
您还没有包含cometd javascript库。这必须在包含jquery.cometd.js之前完成。jquery.comet-d.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>