我爲你寫了簡單的HTML。 Demo at http://jsfiddle.net/UC2dM/185/
$.ajax({
url:'/echo/xml/',
data: {xml:'<Books><book><title>C++</title><author>A</author> </book><book><title>XML</title><author>X</author></book></Books>'},
dataType: 'xml',
type:'post',
success: function(data){
var xml = $(data);
$('#container').append(CategoryToUl(xml.children()));
}
});
function CategoryToUl(xml){
var categories = xml.children('book');
if (categories.length > 0)
{
var ul = $('<ul/>');
categories.each(function(){
var $this = $(this);
var li = $('<li/>');
var a = $('<a/>',{
text: $this.children('title').text()
});
li.append(a);
li.append(CategoryToUl($this));
ul.append(li);
});
return ul;
}
return null;
}
你有試過什麼嗎? – Jai 2013-02-18 17:39:03
你看過嗎:http://api.jquery.com/jQuery.parseXML/? – 2013-02-18 17:40:08
Hello Lakhae,試試這個http://killertilapia.blogspot.in/2011/03/using-jquery-to-read-external-xml-file.html – 2013-02-18 17:41:48