jquery - How can I render a grails model to javascript using a post method from a controller action? -


at jquery event want call upon controller action , use data. way did until was:

$('#my-button').click(function(){ $.post("${createlink(controller: 'myview', action: 'myaction')}", {param1: x, param2: y}, function(data){     //in here want use both elements of model see fit. })  }); 

my controller method looks this:

def myaction(param1, param2){ //some data manipulation goes here  render model: [returnvalue1: variable1, returnvalue2: variable2]; } 

my question how can access variable1 , variable2 $.post method? if don't use model , return 1 of variables, data equal variable, in case won't.

can tell me how access variables in model please? calling ${returnvalue1} not work in function.

you can render json object representing model. here's render documentation

render(contenttype: "text/json") {     [returnvalue1: variable1, returnvalue2: variable2] } 

or

render([returnvalue1: variable1, returnvalue2: variable2] json) 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -