How to find/extract data from xml with jQuery

后端 未结 2 1965
夕颜
夕颜 2020-12-31 20:40

I\'m trying to extract the StateLongName and StateShortName values from the xml below.

I know there has to be a simple elegant way to do this with jQuery.



        
2条回答
  •  情歌与酒
    2020-12-31 21:24

    $.ajax({
                 type: "GET",
                 url: "labels.xml",
                 dataType: "xml",
                 success: function(xml) {
                     $(xml).find('label').each(function(){
                         var id_text = $(this).attr('id')
                         var name_text = $(this).find('name').text()
    
                         $('
  • ') .html(name_text + ' (' + id_text + ')') .appendTo('#update-target ol'); }); //close each( } }); //close $.ajax(

    sample xml for this:

    
    
    
    
       
       
       
       
     
    

提交回复
热议问题