View Full Version : How to receive model via ajax

10-08-2014, 08:29 AM

I have two questions one major one minor. My minor question is why does this simple grails app not work?

Person Domain

package ajax

class Person {
String firstname
String lastname
int age

static constraints = {

package ajax
class HomeController {

def index() {
render (view: "index")
def greet()
render "hi"
def getPersons()
def persons = Person.getAll()
render(model: [persons:persons])

<%@ page contentType="text/html;charset=UTF-8" %>
<g:javascript plugin="jquery" />

<div id="greeting"></div><br>
<button onclick='<g:remoteFunction action="greet" update="greeting"/>'>Click on me!</button>
And finally my major question is, in index.gsp if I wanted to change the button action to getPersons, then how would I get the data via ajax or jquery e.g. g:remoteFunction .And if I did get the data how would I format the data in #greeting so I get the firstname and lastname.

16-11-2014, 10:10 PM
I know its a little late but if you still want help then let me know .. what problem you having with your app ?