title: ajax html vs xml/json responses - performance or other reasons
body: <p>I've got a fairly ajax heavy site and some 3k html formatted pages are inserted into the DOM from ajax requests.</p>
  
  <p>What I have been doing is taking the html responses and just inserting the whole thing using jQuery. </p>
  
  <p>My other option is to output in xml (or possibly json) and then parse the document and insert it into the page. </p>
  
  <p>I've noticed it seems that most larger site do things the json/xml way. Google Mail returns xml rather than formatted html. </p>
  
  <p>Is this due to performance? or is there another reason to use xml/json vs just retrieving html?</p>
  
  <p>From a javascript standpoint, it would seem injecting direct html is simplest. In jQuery I just do this</p>
  
  <pre><code>jQuery.ajax({
      type: "POST",
      url: "getpage.php",
      data: requestData,
      success: function(response) {
          jQuery('div#putItHear').html(response);
      }
  </code></pre>
  
  <p>with an xml/json response I would have to do </p>
  
  <pre><code>jQuery.ajax({
      type: "POST",
      url: "getpage.php",
      data: requestData,
      success: function(xml) {
          $("message",xml).each(function(id) { 
              message = $("message",xml).get(id); 
              $("#messagewindow").prepend("&lt;b&gt;" + $("author",message).text() + 
              "&lt;/b&gt;: " + $("text",message).text() + 
              "&lt;br /&gt;"); 
          });
      }
  });
  </code></pre>
  
  <p>clearly not as efficient from a code standpoint, and I can't expect that it is better browser performance, so why do things the second way?</p>