在我看来,我有
<g:render template="/common/notifications" model="[userNotifications:userNotifications]" />
在 javascript 中,我有一个 ajax 调用来返回 Notification
的 JSON 对象
调用的 Controller 方法如下:
def getNotifications()
{
def userNotifications = Notification.findAllByUser(UserUtils.getCurrentUser())
render userNotifications as JSON
}
但我不知道如何获取响应数据来为模板提供模型
非常感谢任何帮助
最佳答案
不渲染对象,而是渲染模板。让你的 ajax 期望返回 HTML:
render(template: '/common/notifications', model: [userNotifications: userNotifications])
关于ajax - 使用 AJAX 和 JSON 更新 grails 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16363606/