Posted By

vagrantradio on 02/16/10


Tagged

css ajax table data html xml jquery striping


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

emregulcan


JQUERY / AJAX PARSE XML TO TABLE


 / Published in: jQuery
 

URL: http://www.vagrantradio.com/2009/10/how-to-parse-xml-using-jquery-and-ajax.html

jQuery Ajax function to load xml data into a table and add class to even rows for striping.

  1. $(document).ready(function() {
  2. $.ajax({
  3. type: "GET",
  4. url: "data.xml",
  5. dataType: "xml",
  6. success: parseXml
  7. });
  8. function parseXml(xml) {
  9. $(xml).find("location").each(function() {
  10. //find each instance of popupTitle in xml file
  11. var popupTitle = $(this).find("popupTitle").text();
  12. //if blank hide row
  13. if (popupTitle == "") {
  14. $("table#table tbody tr").hide();
  15. } else {
  16. //else add tr and td tags and add alt class for striping
  17. $("table#table tbody").append("<tr>" + "<td nowrap='nowrap'>" + $(this).find("popupTitle").text() + "</td>" + "<td>" + $(this).find("popupDescription").text() + "</td>" + "</tr>");
  18. $('table#table tbody tr:even').addClass('alt');
  19. }
  20. });
  21. }
  22. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: genxt on July 19, 2011

Try this: http://www.arunraj.co.in/index.php?option=com_content&view=article&id=7:populate-table-using-ajax&catid=4:javascript&Itemid=9

You need to login to post a comment.