ajax - 使用 AJAX 和 JSON 更新 grails 模板

标签 ajax templates grails

在我看来,我有

<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/

相关文章:

c++ - 在编译时生成 BitCount LUT

模板的 C++ 错误和推导的参数冲突类型

eclipse - 用于 Grails 开发的工具

forms - grails表单重定向给出404,但是URL映射有效

javascript - Ajax请求说提交数据成功但是php没有响应

javascript - Underscore.js Debounce 无法与 Scroll 一起正常工作

javascript - WebApi 2 中的同步 XMLHttpRequest

javascript - 在 Google 地理编码中使用回调函数

python - 如何在 google-app-engine 模板中启用方法

tomcat - 我可以将 Grails 设置为自动编译而不调用 run-app 吗?