XML parsing using jQuery

后端 未结 3 661
孤独总比滥情好
孤独总比滥情好 2021-01-16 12:56

I have the following xml:




        
3条回答
  •  死守一世寂寞
    2021-01-16 13:18

    This code works for me in Safari and (surprisingly) Firefox:

    $.ajax({
        type: "GET",
        url: "list.xml",
        dataType: "xml",
        success: function(xml) {
      $(xml).find('Scenes').each(function(){
          $(this).find('Scene').each(function(){
              var name = $(this).attr('Name');                            
              $('
    ').html('

    '+name+'

    ').appendTo('#page-wrap'); }); }); }, error:function(a,b,c) { console.log( c ) } });

    The reason it doesn't work in some browsers is likely due to the fact that you're hosting from the filesystem (assuming you are). Chrome and Firefox tend to give trouble when accessing the filesystem via AJAX request due to Same Origin Policy.

    The javascript is fine. You're just either getting an empty response, or an error.

    This question may be applicable:

    Problems with jQuery getJSON using local files in Chrome

提交回复
热议问题