Which is better in AJAX request, Response with ready HTML or response with just data and write HTML using JavaScript, and this JavaScript will use a predefined HTML template to put the coming data inside and show on the page.
Creating the HTML on the server and send to the page, will decrease the client side JS code, but will increase the response size.
Sending the data to the client side will decrease the response size but will increase the JS code.
Which is better and most used?
I think the right solution is highly context dependent. There may be a right answer for a given situation, but there is no one size fits all answer. Generally, if I’m using a partial view that gets replaced via AJAX, I’ll return html. If I’m performing an action on a small part of something, I’ll use JSON. I’m probably more likely to use JSON as there are more situations where it fits, but I try to pick the best solution for the problem at hand. I’m using ASP.NET MVC, though. Other frameworks undoubtedly have different characteristic solutions.