0

Don't understand some groovy grails details. I have controller LogsController, and i have logs.gsp and everything mapped, so when i try to get /logs/applog - getting logs.gsp or some data from render. So the question is: how can I return a variable? I want to do something like that: opening page (logs/applog) -> closure returns (renders?) variable as JSON -> page logs.gsp gets that variable, parse it with javascript and show data. But if I write

render var as JSON;

getting just JSON and don't see page logs.gsp How i can do this? Thanks.

Gwalk
  • 211
  • 4
  • 13

1 Answers1

1

render(view: 'logs', model: [var: var]) will send variable var from controller to logs.gsp. In gsp file, you can access by using ${var}. All of this will be done in server side so you don't need JSONObject.

In your case, If you want to get JSON variable and use javascript to access it:

  • In gsp file you need a ajax request
  • In controller, check ajax request. If it's is ajax request, do render var as JSON to return JSON Object to client. If not, do render(view: 'logs', model: [var: var]) to return a page as normal.
Community
  • 1
  • 1
hakuna1811
  • 524
  • 5
  • 11