When it comes to returning data from an XmlHttpRequest, there are several options to consider. Here's a breakdown:
Plain HTML: The request can format the data and return it in a user-friendly way.
Advantage: Easy for the calling page to consume.
Disadvantage: Limited flexibility due to fixed layout.XML: The request can return XML which can be formatted using XSLT on the calling page.
Advantage: Can easily be consumed by other sources.
Disadvantage: Dependence on browser support for XSLT.JSON: The request can return JSON which can be consumed and rendered in HTML using Javascript.
Advantage: Easier to organize javascript code.
Disadvantage: May not be as straightforward as the other options.
I have also considered combining option one with abstracting the view logic in the called service to allow for easy switching of layouts. Personally, I believe this is the most compatible option.
Another idea that crossed my mind is whether it would be beneficial to accommodate all three response formats based on a parameter added to the request. What do you think?