Using jQuery .each to loop over XML file

后端 未结 1 1275
灰色年华
灰色年华 2020-12-11 05:26

I have an XML file that is pretty long. Below is the code I am using to retrieve the file and then go through the file using jQuery\'s .each(), outputting the correct infor

相关标签:
1条回答
  • 2020-12-11 06:12

    Try using parseXML before you find the element

    $(document).ready(function(){
      $.ajax({
        type: "GET",
        url: "data.xml",
        dataType: "xml",
        success: function(xml) {
            $.parseXML(xml).find('Table').each(function(index){
                var provider = $(this).find('Provider').text();
                var channel = $(this).find('FeedCommonName').text();
                var hd = $(this).find('FeedIsHD').text();
                $('.box ul').append('<li>'+channel+'</li>');
            });
        },
        error: function() {
            $('.box ul').text("Failed to get xml");
        }
      });
    });
    
    0 讨论(0)
提交回复
热议问题