/ Published in: jQuery
jQuery Ajax function to load xml data into a table and add class to even rows for striping.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function() { $.ajax({ type: "GET", url: "data.xml", dataType: "xml", success: parseXml }); function parseXml(xml) { $(xml).find("location").each(function() { //find each instance of popupTitle in xml file var popupTitle = $(this).find("popupTitle").text(); //if blank hide row if (popupTitle == "") { $("table#table tbody tr").hide(); } else { //else add tr and td tags and add alt class for striping $("table#table tbody").append("<tr>" + "<td nowrap='nowrap'>" + $(this).find("popupTitle").text() + "</td>" + "<td>" + $(this).find("popupDescription").text() + "</td>" + "</tr>"); $('table#table tbody tr:even').addClass('alt'); } }); } });
URL: http://www.vagrantradio.com/2009/10/how-to-parse-xml-using-jquery-and-ajax.html