Accessing the AJAX response and updating the table with new values
I am confused with the handling of the response of the server, when submitting an AJAX request. What I would like to do, is an update of a table by clearing it and inserting the new ones.
The following code of the controller gives a resonse to an ajax request, triples is a list:
def resultsAjax = {
def triples = linkedDataService.getRemoteTriplesTable("Student4")
render(template:'tripleResultsTable', model:[triples:triples])
}
This is the form:
<g:form action="results">
<label for="id">Resource ID </label>
<g:textField name="id" />
<g:submitToRemote value="search" update="resultsAjax"
url="[controller:'tripleProperty', action:'resultsAjax']"/>
</g:form>
And the table below:
<g:render id="resultsAjax" template="tripleResultsTable" model="${triples}"/>
How can I access the list that is responded from the server?
EDIT:
It works more or less, but strange thing is, that the table is not updated, but the new values are on top of the table...
The template is just this:
<g:each in="${triples}" status="i" var="tripleProperty">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<开发者_开发知识库td>${tripleProperty.property}</td>
<td>${tripleProperty.value}</td>
</tr>
Does it need some more code than render(template..) to replace the values in the table?
What does your tripleResultsTable.gsp template look like? You probably the model attribute to look like this
<g:render id="resultsAjax" template="tripleResultsTable" model="${[triples:triples]}" />
Then in your template you can use
<g:each in="${triples}">...</g:each>
to ouput the TR/TD elements you want
cheers
Lee
精彩评论