Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery中的XML解析-第三级节点_Javascript_Jquery_Xml - Fatal编程技术网

Javascript jQuery中的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:

<?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);
        });