Ajax retrieval of references now working
Posted by mholmes on 22 Dec 2009 in Activity log
I now have the retrieval of references by Ajax working. This is the deal:
- Some reference items link to other reference items. When we retrieve a document from the db, we automatically retrieve all references which are linked from the original document, and add them to the output page, so they can be shown as required; but we can't easily parse all the retrieved references to see if they have links to other references, because this kind of recursion is potentially infinite.
- Therefore the JavaScript
showReferences()
function does this:- Check if the reference exists in the document. If it does, show it as normal.
- If it doesn't, then:
- Construct a URL to retrieve the reference, and set the targetEl element to the
<div>
that contains the current list of references. This means the Ajax function will append the retrieved element to the list of references in the document. - Construct a string which calls the
showReference()
function again, and store that in theonAjaxComplete
variable. The Ajax code, when it completes, checks whether this is null or not, and if it's not null, it calls it witheval()
. - When the
showReference()
function is called a second time, the item now exists in the document, so it can be shown in the normal way. - There's a trap for when the retrieval fails, to stop infinite loops.
- Construct a URL to retrieve the reference, and set the targetEl element to the
This entry was posted by Martin and filed under Activity log.