Example 4: Debug Information (and How Does Taconite Work?)

By now you're quite familiar with using Taconite. In a nutshell, all you have to do is create an AjaxRequest object, provide it with the endpoint URL, optionally add any query parameters, and send the request. On the server side, simply write the XHTML that you want to appear on the page, embed it within some simple Taconite-specific XML tags, and send the response back to the browser. Taconite handles the rest.

What if the server isn't sending back the response you think it is? Debugging within the server environment can often be tricky and error-prone. Or, what if the Taconite parser isn't working the way you think it should be? How can you dig into the "guts" of Taconite?

Taconite may not be able to fix your bugs for you, but it does provide a simple console that can help you track down and fix problems. Adding one simple line to your JavaScript will tell Taconite tell print the server's response XML out to a text area on the Web page. If parsing performed on the browser, then the results of the parsing operation will also be shown in a text area. All you have to do to enable this debugging information is to call a single method on the AjaxRequest object. Taconite handles the rest for you.

Enabling Debugging Information

The AjaxRequest object provides a method called setEchoDebugInfo(). Calling this method before sending the Ajax request will tell Taconite to write debugging information to the Web page where you can easily see it. That's all you need to do -- Taconite does the rest!

Listed below is the doHelloWorld() function from Example 1. Note that the only change is to call the setEchoDebugInfo() function before calling the send() method:

01         <script type="text/javascript">
02             function doHelloWorld(url) {
03                 var ajaxRequest = new AjaxRequest(url);
04                 ajaxRequest.setEchoDebugInfo();
05                 ajaxRequest.sendRequest();  
06             }
07         </script>

Try it yourself and see what happens. You'll be able to easily see the result sent by the server, and the results of any parsing that occurred within the browser.

While you're looking at the debug information, take a moment to look at the JavaScript produced by the Taconite parser. It should be nearly identical to the JavaScript you would write to do the same task -- except you didn't have to write it yourself, and you didn't have to worry about browser compatibility. Taconite handled all of this for you. All you had to do was write XHTML. You can see that Taconite avoids the use of the innerHTML property and that the JavaScript (for the most part) strictly adheres to W3C and ECMAScript standards. It only deviates from these standards when necessary to ensure wide browser compatibility.


The AjaxRequest object provides the setEchoDebugInfo() method which tells Taconite to write the server's response and the results of any parsing operations to the Web page for easy viewing. This can be used to debug problems and also as a learning tool to understand what Taconite is doing under the covers.