从ajax请求返回HTML

How to properly return html from an ajax call? Im currently returning html inside json but is there a better way to handle this? How to handle errors and missing arguments for example. Should an ajax request return always JSON?

<?=json_encode(array('html' => $res))?>

I recommend you use HandleBars (http://handlebarsjs.com/) or another client side template engine to render JSON into HTML.

Then your JSON will contain only the data. It will be rendered as HTML and the presentation controlled by CSS.