Need advice on using Grails and Ajax to append to a div like in Rails
Posted
by Nate
on Stack Overflow
See other posts from Stack Overflow
or by Nate
Published on 2009-06-12T15:42:25Z
Indexed on
2010/03/16
7:06 UTC
Read the original article
Hit count: 420
I'm just starting out in Grails and need some advice on using Ajax. I want to append some html to the bottom of a div inside a form. This is basically what I have:
-form- -div id="listOfchildren"- childrow 1 input fields childrow 2 input fields childrow 3 input fields -/div- -form- -a-Add Child 4-/a-
When I click on the "Add Child" I want to make an ajax call that results in a new childrow getting inserted into the "listOfchildren" div. So the document would look like this:
-form- -div id="listOfchildren"- childrow 1 input fields childrow 2 input fields childrow 3 input fields childrow 4 input fields -/div- -form- -a-Add Child 5-/a-
In Rails I would do something simple like this:
render :update do |page| page.insert_html :bottom, "list_of_children", :partial => child_partial page.replace "add_link", :partial => 'add_link' end
The previous code sends an javascript back to the browser with two commands. The first command tells the browser to append some html to the bottom of a div. The second command updates the "add link" counter.
In grails I can only see how to replace an entire div (which would wipe out the user's existing input) and I don't see how I can call multiple functions from the ajax response. I can probably do this if I was to write some javascript functions in prototype or whatever, but I'd like to avoid that if there is a simpler way.
Thanks!
Nate
© Stack Overflow or respective owner