My goal is to add two select boxes within the results div using Ajax. I have a function named ajaxFun that retrieves values for the select boxes. However, I am struggling with rendering multiple objects as JSON and then retrieving them in my JavaScript function.
This is my GSP page:
<table>
<tr>
<td><div id="test" onclick="${remoteFunction(controller:'ProjectOperations', action:'ajaxFun', update:'results',onComplete:'getFields(e)',params:'\'filter=\' + escape(this.id)' )}">click me!</div></td>
</tr>
</table>
<div id="results"></div>
Controller class:
import grails.converters.JSON
class ProjectOperationsController {
def ajaxFun(){
def project="Hill"
def company="VK"
def operation=Operation.findAllByProject_name(project)
def staff=StaffDetails.findAllByCompany_name(company)
render operation,staff as JSON
}
}
In this part, I aim to render two lists (operation and staff respectively) and also learn how to retrieve them from the JavaScript function.
Javascript function:
<g:javascript>
function getFields(e){
// here I want to retrieve those two objects.
}
</g:javascript>