【发布时间】:2011-10-23 14:57:41
【问题描述】:
我有 4 个 xml 块,我想用 jQuery 进行一次 ajax 调用来解析它们。现在四个xml块彼此不同(但结构相同)。我试图通过向每个 xml 块传递一个 id 来解析这个 xml,但是在我的 ajax 调用中,我无法检索 id 属性,因为它是我需要捕获以传递给 ajax 函数的第一件事。
我尝试过这样的事情:
XML 在这里:
<dropdown>
<test id="1">
<optionheading>
<heads>Heading 1</heads>
<value>
<values images='images/1.gif'>Option1</values>
<values images='images/2.gif'>Option2</values>
<values images='images/3.gif'>Option3</values>
</value>
</optionheading>
.....................................
............................
</test>
<test id='2">
<optionheading>
<heads id="b">H..................
..................
............
</test>
</dropdown>
我需要获取 test1、test2、et-al 的 id
Ajax 来了:
$("document").ready(function() {
$.ajax({
type: "GET",
url:"dropdown.xml",
dataType: "xml",
success :function(xml) {
var select = $("#mySelect");
//I am getting id here
var id=$(xml).find('test').attr('id');
$(xml).find('test'+id).each(function() {
$(this).find('optionheading').each(function() {
var opthead = $(this).fin......................
【问题讨论】:
标签: jquery xml ajax xml-parsing