Grails气氛插件问题
我在 Grails 应用程序中使用 Atmosphere 插件来向客户端进行 Ajax 推送调用。基本架构是,我在服务器中有一个循环,它创建我想要推送到浏览器的数据,因此在每次迭代中它都使用气氛广播()方法将数据发送到客户端。
当我在循环外使用它时它工作正常,如下所示:
def builder = new JSONBuilder()
def jsonResult = builder.build{
artist = "incubus"
location = {
lat = 45.678909
lng = -14.45667
}
}
broadcaster['/atmosphere/recommend'].broadcast(jsonResult)
但是,当我在循环内以编程方式使用它时,浏览器会抛出错误:指定了无效或非法字符串“代码:”12 ,并且无法正常工作。
循环的简化示例如下:
[[lat:45.678909,lng:-14.45667],[lat:32.56433,lng:22.4566]].each{
def builder = new JSONBuilder()
def jsonResult = builder.build{
artist = "incubus"
location = {
lat = '"${it.lat}"'
lng = '"${it.lng}"'
}
}
broadcaster['/atmosphere/recommend'].broadcast(jsonResult)
}
有什么想法为什么会发生这种情况吗? 谢谢!
I'm using the Atmosphere plugin in a Grails application to make Ajax push calls to the client. The basic architecture is, I have a loop in the server which creates the data that I want to push to the browser, so in every iteration it uses the atmosphere broadcast() method to send the data to the client.
It works fine when I use it outside the loop, like this:
def builder = new JSONBuilder()
def jsonResult = builder.build{
artist = "incubus"
location = {
lat = 45.678909
lng = -14.45667
}
}
broadcaster['/atmosphere/recommend'].broadcast(jsonResult)
However, when I use it programmatically inside the loop, the browser throws the error: An invalid or illegal string was specified" code: "12, and doesn't work properly.
A simplified example of the loop is as follows:
[[lat:45.678909,lng:-14.45667],[lat:32.56433,lng:22.4566]].each{
def builder = new JSONBuilder()
def jsonResult = builder.build{
artist = "incubus"
location = {
lat = '"${it.lat}"'
lng = '"${it.lng}"'
}
}
broadcaster['/atmosphere/recommend'].broadcast(jsonResult)
}
Any ideas why is this happening?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果您删除引号,它应该可以工作。
基督教
I think it should work, if you remove the quotes.
Christian