Even as at first I commonly send HTML
to be inserted at specific places, now I tend to use JSON
whenever I can, XML
otherwise, mainly because I can modify a lot of places of the page, and act more dynamically with little information.
Also, JSON
has a smaller footprint than XML
and is also usually better "human parseable". XMl's biggest advantage is that it has been around for a long time and is the standard, so you have both the tools, and the knowledgeable workforce at hand for it. JSON, on the other hand is a little more obscure. Of course, any developer worth its paycheck will be able to learn it faster than I can write this. Just think about it:
- it has javascript syntax and
- its the same concept of XML.
About just sending HTML
Quirksmode says:
If the HTML snippet contains forms, or if the receiving HTML element is a form, this method give horrific errors in Explorer.
(...)
I'm going to study JSON carefully and might switch to it for an unrestricted access application I have in mind. Nonetheless I feel that XML remains the best overall format for the time being, mainly because people are used to it.
In addition, HTML snippets may become quite complicated (...) Thus the server side script that generates the HTML may become quite complicated.
Furthermore, by sending just HTML you can just paste information, you won't be getting information, you'd be getting snippets, so you couldn't operate with it. Remember that the advantage of AJAX is to have dynamic pages, not pages that have some parts that update without reloading the full page. You can use it for that, and is OK, and a valid use, but you are under utilizing the potential.
Even when inserting HTML could be faster than dom
manipulation, I don't think that its that much (besides the problems you could have with IE 6). This you should test and see if for your use, its really a bottle neck of performance.
I tend to agree with the closing argument of the previous link.
Although I'd love to be able to say that one of them is "the best", I think choosing the right format depends on the circumstances, and not on any theoretical musings.