Example 1
Take a look at this simple XML response:
<taconite-root> <taconite-append-as-children selector="#home"> <![CDATA[ <div>hello world!</div> ]]> </taconite-append-as-children> </taconite-root>
Here's the description of the response:
- Be sure the content type of the response is text/xml.
- Note the taconite-root root element.
- There is one action: a taconite-append-as-children element. This element tells the parser that the contents of that element (the div containing the text hello) should be appended to the DOM node(s) specified by the "selector" attribute.
- The selector attribute's value of "#home" tells the parser to append the contents of the element to the DOM element that has an ID of "home". Remember that the value of the selector attribute is simply a jQuery selector.
Example 2
This is a slightly more advanced example that uses multiple Taconite actions. Updating the DOM in multiple ways as a result of a single Ajax request is a powerful feature of Taconite.
<taconite-root> <taconite-replace-children selector="#searchResults"> <![CDATA[ <tbody> <tr> <td>First Name</td> <td>Last Name</td> </tr> <tr> <td>George</td> <td>Washington</td> </tr> </tbody> ]]> </taconite-replace-children> <taconite-insert-before contextNodeID="content"> <![CDATA[ <p class="alert">Search results updated.</p> ]]> </taconite-insert-before> </taconite-root>
Here's the breakdown of the response XML:
- Be sure that the content of the response is text/xml.
- Note the taconite-root root element.
- Note how the contents of each action are enclosed in a CDATA element.
- The taconite-replace-children element tells the parser to replace child elements of the DOM element(s) specified by #searchResults (in this example it's probably a table element) with the content that's enclosed in the CDATA section of the taconite-replac-children element.
- The taconite-insert-before element tells the parser to insert the content specified in the element's CDATA section *before* the DOM element that has and ID of "content". Note that instead of using the selector attribute, this example uses the contextNodeID attribute from previous versions of Taconite.