I am writing an application - a screen using Java Servlets on the server side, which is supposed to display some data in 3 tables.
That seems like a lot of work. Am I taking the wrong approach here and missing a shortcut?
Well the optimum approach would be to DOM-script your table in your JS, when the AJAX response is received. But it depends on the nature of your table and whether you can trust that to automated process or whether you need to put certain values in certain TDs in certain situations.
AJAX returns either XML or text, but a common approach is to return JSON-parsed text. This is basically text parsed as a JS object, e.g.
To the OP, it's your lucky day! Want to hear something cool? That's the exact approach I use and, because of that, I wrote a function that takes XML and recursively converts it to HTML and appends it to the dom element that you specify!!
You may have found the advantage in this method is that you use the same server side code to display a page/part of a page whether it is requested via AJAX, or a genuine (for lack of a better term) HTTP request such as when you click on a link/submit a form.
In the above code, domnode is a reference to a node where the contents of responseXML will be APPENDED. If you want to replace the entire contents of domnode, then just delete all child nodes first using: