我的 url 有以下 xml 返回:
<?xml version="1.0"?>
<categories>
<category>
<catid>17</catid>
<name>Collage</name>
<parent></parent>
</category>
<category>
<catid>15</catid>
<name>Letter Mats</name>
<parent></parent>
</category>
<category>
<catid>182</catid>
<name>Single Opening</name>
<parent></parent>
</category>
</categories>
而我的javascript代码,我有:
var matte_select_options = new Array();
function matte_designs_populate_types()
{
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "myurl/system/components/catsxml/3",
dataType: 'xml',
success: function(xml) {
designs = xml.getElementsByTagName("categories")[0].childNodes;
var output = [];
alert(designs.length);
for (i = 0; i < designs.length; i++)
{
var catid = designs[i].getAttribute("catid");
var name = designs[i].getAttribute("name");
output.push('<option value="'+ catid +'">'+ name +'</option>');
matte_select_options[catid] = name;
}
$('#matte_designs').html(output.join(''));
}
});
});
}
出于某种原因,警报给了我 7,我不知道为什么。但是,主要问题是 select 没有填充,因为 catid 和 name 甚至没有被设置。