Javascript jQuery中的XML解析-第三级节点
我有这样一个XML:Javascript jQuery中的XML解析-第三级节点,javascript,jquery,xml,Javascript,Jquery,Xml,我有这样一个XML: <?xml version="1.0"?> <service> <name>My Element</name> <header>My Header</header> <sections> <section> <!-- Optional --> <subheader>Su
<?xml version="1.0"?>
<service>
<name>My Element</name>
<header>My Header</header>
<sections>
<section>
<!-- Optional -->
<subheader>Subheader 1</subheader>
<description>Here goes the content</description>
</section>
<!-- Optional -->
<section>
<subheader>Subheader 2</subheader>
<description>Here goes the content</description>
</section>
</sections>
</service>
我认为$(这个)是$的本地循环,但看起来我错了。有人能帮忙吗
谢谢
注意,在原始帖子中,
var subheader=$(此)。查找('subheader')。文本代码>在之后似乎没有()
。text
试一试
是的,解决了!这样愚蠢的错误。必须将.text更改为.text()。非常感谢您指出这一点:)
function getDescription(descriptor_url) {
var descriptor_object = $.get(descriptor_url, function(descriptor_data, descriptor_status, descriptor_response) {
$(descriptor_response.responseXML).each(function () {
//this works fine
var header = $(this).find('header').text();
});
$(descriptor_response.responseXML).find('sections').each(function() {
// here is where the issue is
$(this).find('section').each(function() {
var subheader = $(this).find('subheader').text;
// Included a screenshot of this alert here
alert(subheader);
})
})
})
.fail(function() {
response.value = "Something went wrong with the request.\n\nReason: " + descriptor_object.statusText;
})
}
$(descriptor_response.responseXML).each(function () {
//this works fine
var header = $(this).find('header').text();
var subheaders = $(this).find("sections section subheader").text();
var descriptions = $(this).find("sections section description").text();
alert(header + "\n" + subheaders + "\n" + descriptions);
});