ajax html vs xml/json responses - performance or other reasons

前端 未结 8 1300
死守一世寂寞
死守一世寂寞 2020-12-05 09:58

I\'ve got a fairly ajax heavy site and some 3k html formatted pages are inserted into the DOM from ajax requests.

What I have been doing is taking the html responses

8条回答
  •  佛祖请我去吃肉
    2020-12-05 10:31

    In some cases, AJAX responses need to return more information than just the HTML to be displayed. For example, let's say you are returning a list of the first twenty items from a search. You may need to return the total number of search results to be displayed somewhere else in the DOM. You could try piggybacking the total count in a hidden div, but that can get messy. With JSON, the total count can simply be a field value a structured JSON response.

提交回复
热议问题