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

前端 未结 8 1290
死守一世寂寞
死守一世寂寞 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条回答
  •  -上瘾入骨i
    2020-12-05 10:43

    Here are a few pros for sending JSON/XML instead of HTML:

    1. If the data is going to ever be used outside of your application HTML might be harder to parse and fit into other structure
    2. JSON can be directly embedded in script tags which allows cross domain AJAX scenarios
    3. JSON/XML preserves the separation of concerns between the server side scripts and views
    4. Reduces bandwidth

提交回复
热议问题