Json和HTML显示

I have a service I programmed to generate news. There is ATM close to 30 news types, each with different HTML code to display. For each case I get from the JSON returned by AJAX call the variable parts only, then generates the wanted HTML in JS and appends it to the container.

I found it very hard to work with, and a pain to debug. A lot of HTML generated in the JS looks to me like a bad thing. But I want the response from the server to be as light as it can, so I don't want to send back the whole HTML each time, it's so much better to send back only a little JSON.

Any idea of how I should do ?

Thanks ahead !

Use a good template engine like http://handlebarsjs.com/. They also have debug handlers

Easy way is to use Angular Directives. That will make the html well organized and easy to read( if you are modeling the JSON at Client Side).

Angular got may features which will help in your case ( Typically News, Blogs sites).