使用AJAX和JSON更新grails模板

时间:2013-05-03 16:30:11

标签: ajax templates grails

在我看来我有

<g:render template="/common/notifications" model="[userNotifications:userNotifications]" />

在javascript中我有一个ajax调用来返回Notification s的JSON对象

调用的控制器方法如下:

def getNotifications()
{
    def userNotifications = Notification.findAllByUser(UserUtils.getCurrentUser())      

    render userNotifications as JSON
}

但是我不知道如何获取响应数据来为模板提供模型

非常感谢任何帮助

1 个答案:

答案 0 :(得分:4)

不是渲染对象,而是渲染模板。让你的ajax期待HTML作为回报:

render(template: '/common/notifications', model: [userNotifications: userNotifications])
相关问题