How to receive model via ajax

F

fityf

Guest
All,

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

Code:
Person Domain

package ajax

class Person {
    String firstname
    String lastname
    int age


    static constraints = {
    }
}
HomeController

package ajax
class HomeController {

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

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

<body>
<div id="greeting"></div><br>
<button onclick='<g:remoteFunction action="greet" update="greeting"/>'>Click on me!</button>
</body>
</html>
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.
 
Top