我正在尝试使用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 中编写的
是否有我不知道的已知问题,或者我做错了什么?
感谢您提供有关如何找出从未调用回调的原因的提示。
您正在尝试使用cometD。
根据cometD的参考手册,您需要用cometD Primer下载中提供的文件替换标准Dojo工具包的一些js文件。
使用cometD的文档,你会在合理的时间内让你的应用程序正常运行。