tags:

views:

19

answers:

1

I have a GSP with a form for submitting a search that updates a div on the page via an Ajax call:

<g:submitToRemote value="Search"
   update="employeeList"
   url="[controller: 'employee', action: 'searchAjax']" />

My EmployeeController has the searchAjax action:

def searchAjax = {
   def employees = employeeService.search(params.searchTerm)
   render(template: 'employeeListing', collection: employees, var: 'employee')
}

Unfortunately the rendered output always includes my controller's layout. Is there a way to have the render() method only render the template without the layout?

+1  A: 

Never mind. I found this. I was initially confused by that post because the author misunderstands (and misuses) the word "template". I don't think he understood that Grails actually has templates, which are different from layouts!

Anyway, the answer is to include a 'text/plain' content type argument:

def searchAjax = {
   def employees = employeeService.search(params.searchTerm)
   render(template: 'employeeListing', collection: employees, var: 'employee',
          contentType: 'text/plain')
}
Eric