简体   繁体   中英

Generate ul with jquery each and xml

I'm trying to populate a ul with <li> elements for each "row" tag inside of my XML document. Right now I just want it to display an arbitrary text until I can figure out why this is not even working, then I'll work on adding actual values from the file. #results is the <ul>.

 function getXML () { $.ajax({ type: "GET", url: "garbage.xml", dataType: "xml", success: generateList }); }; function generateList (xml) { $(xml).find('Row').each(function() { $('#results').append( '<li class="results__item">1</li>' ); }); } $(document).ready(function() { getXML(); }); 

Here's a sample of the xml

 <?xml version="1.0" encoding="windows-1252" standalone="yes"?><!-- Generated by abcexcel--> <Records> <Record> <Row A="TITLE" B="ALT_WORDS" C="DESC_ID" D="DESCRIPTION" /> </Record> 

All it does is repeat more records.

Try to change the getXML function:

function getXML () {
    $.get("garbage.xml", function(data) {
        generateList(data);
    });
}

or to use the ajax function

$.ajax({
   type: "GET",
   url: "garbage.xml",
   dataType: "xml",
   success: function(xml) { 
       generateList(xml);
   });   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM