weixin_33744854 2015-12-22 00:33 采纳率: 0%
浏览 36

从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))?>
  • 写回答

1条回答 默认 最新

  • weixin_33725515 2015-12-22 00:38
    关注

    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.

    评论

报告相同问题?