如何使用 jQuery 读取和签署 XML 数据(不同大小的数组)?
AJAX 从 XML 读取行节点并存储在 javascript 数组中,在 XML 数组中的大小不是恒定的。
我的代码:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "sites.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('msg').each(function() {
var title = $(this).find('title').text();
i = 0;
tic = new Array();
$(this).find('desc').each(function() {
tic.push($(this).find('line').text());
alert(tic[i]);
i++;
});
});
}
});
});
和 XML 文件(演示)
<msgs>
<msg>
<title>ABC</title>
<desc>
<line>test 1</line>
<line>test 2</line>
<line>test 2</line>
</desc>
<time>5</time>
</msg>
</msgs>
有人可以帮我吗