在grails中使用大气插件,在向服务器发出一些请求之后(在几页导航之后),浏览器没有呈现任何页面而只是加载。其他系统中的其他浏览器工作正常。连接到服务器的代码放在公共布局页面中。 服务器代码:
def onRequest = { event ->
def userBroadcasters= ServletContextHolder.servletContext.getAttribute('userBroadcasters')
def uid=event.getRequest().session.user?.id
if(!userBroadcasters){
userBroadcasters=[:]
}
Broadcaster privateChannel = BroadcasterFactory.getDefault().lookup("/userChannel"+uid, true);
privateChannel.addAtmosphereResource(event)
userBroadcasters.put(uid,privateChannel)
ServletContextHolder.servletContext.setAttribute('userBroadcasters',userBroadcasters)
event.suspend()
//println ServletContextHolder.servletContext.getAttribute('userBroadcasters')
//println "Inside onRequest!"
}
常见布局的客户端代码:
function callback(response) {
if (response.status == 200 && response.responseBody.length > 0) {
//action
}
}
var location = '${request.contextPath}/atmosphere/mx';
var request = {transport: "streaming", fallbackTransport: 'long-polling', contentType: "application/json",connectTimeout:4000};
$.atmosphere.subscribe(location, callback, request);