Forum OpenACS Q&A: Using AJAX with xowiki

Posted by Richard Hamilton on
I am trying to understand the most elegant method for interacting with xowiki asynchronously.

To try to understand I took a look at the toc includelet which seems to be the only includelet that uses AJAX (for cosmetic effects).

The Javascript code begins as follows:

            var transaction = YAHOO.util.Connect.asyncRequest('GET', \
                href + '?template_file=view-page&return_url=' + href,
                  success:function(o) {...etc....

This seemed to suggest to me that there is a built-in 'href' xowiki object to which the parameters template_file and return_url were being passed, however requests to the url in a standard installation yield a "Page 'href' is not available." error. (i.e.

Clearly I have mis-understood!

I can see that one way to arrange an AJAX interaction would be to create a plain xowiki page object containing embedded tcl code that extracts and formats the data, but is this the best or recommended method?

Can anyone please explain the above code for me?

Thank you

2: Re: Using AJAX with xowiki (response to 1)
Posted by Dave Bauer on
href is a javascript variable in that code. It must be set elsewhere.

Overall yeah, you need an xowiki template that returns the page content without the template.

What you probably really want to do is use some sort of progressive enhancement so you could tag links etc with a css class and then add a listener for all items of that class that would load the content in the background.

3: Re: Using AJAX with xowiki (response to 2)
Posted by Richard Hamilton on
Thanks Dave, that's helpful to know. I had also looked through the docs for the Javascript Link object but couldn't see how a bare href would refer to a link object. As you say, this variable must be set somewhere, perhaps by the YUI2 connection manager.

I'll have fun trying to track that down. :-)


4: Re: Using AJAX with xowiki (response to 3)
Posted by Richard Hamilton on
Just to round off the thread, the 'href' in question is a property of the YAHOO.widget.TextNode() class which the xowiki toc includelet uses for fetching page content when the user clicks a node on the treeview table of contents.

Mystery solved.

5: Re: Using AJAX with xowiki (response to 4)
Posted by Richard Hamilton on
Oh, dear, I'm very sorry, I was talking rubbish!

'href' in this contect is a method of the toc object created in the preceeding code and passed as an argument into the YAHOO.util.Connect.asyncRequest() as part of the callback definition.

  toc instproc href {book_mode name} {
    my instvar package_id __including_page
    if {$book_mode} {
      set href [$package_id url]#[toc anchor $name]
    } else {
      set href [$package_id pretty_link -parent_id [$__including_page parent_id] $name]
    return $href

Clearly it returns a suitable url based on the node in the toc treeview that has been clicked.  This url is then used to obtain the page content.  It appears that the url is a standard one and I can see no customisation server-side to support the AJAX request.

The responseText property of the response object contains the server's reply which is then inserted into the appropriate page fragment using the innerHTML property.