PDA

View Full Version : How to receive model via ajax



fityf
10-08-2014, 08:29 AM
All,

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 = {
}
}
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.

robmorning
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 ?