2013-05-03 29 views
1

一個Grails模板,我有更新在我看來,使用AJAX和JSON

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

在JavaScript我有一個AJAX調用返回Notification小號

控制器方法的JSON對象被稱爲是如下:

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

    render userNotifications as JSON 
} 

但我沒有線索如何獲得響應數據提供模板與模型

非常感謝任何幫助

回答

3

而不是呈現對象,呈現模板。讓你的AJAX期望HTML的回報:

render(template: '/common/notifications', model: [userNotifications: userNotifications]) 
+0

啊對,所以我認爲它創造了'div'的事項,''的notificationContainer' id'說,然後在成功回調在JavaScript調用'$( '#notificationContainer')。html(data)'?這似乎工作,是做到這一點的正確方法?感謝您的幫助:) – 2013-05-03 17:28:10

+1

是的,這是正確的 – 2013-05-03 18:20:20