Ajax Call Example

The code in the example will return a JSON object to the client containing an array with name, description pairs of all terms in the glossary of the site. This list can then be used to annotate glossary terms on the client.

Smartsite SXML CopyCode image Copy Code
<se:hidden>
    <se:json id="list">{"glossary":[]}</se:json>
    <se:json id="term">{"n":"", "d":""}</se:json>
    <se:sqlquery>
        <se:parameters>
            <se:parameter name="sql">
                select name, description from vwGlossary
            </se:parameter>
            <se:parameter name="rowformat">
                {page.term.set(n, this.field(1), "string")}
                {page.term.set(d, string.normalizewhitespace(this.field(2)), "string")}
                
                {page.list.add(glossary, page.term.get())}
            </se:parameter>
        </se:parameters>
    </se:sqlquery>
</se:hidden>{page.list.get(glossary, true, default='null', error='null')}
{response.contenttype(page.list.mimetype())}