Javascript 从url将XML导入html不起作用

Javascript 从url将XML导入html不起作用,javascript,xml,Javascript,Xml,我想将XML数据显示到表中。脚本是: <script type="text/javascript"> var xhr= window.XMLHttpRequest? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); xhr.onreadystatechange= function() { if (this.readyState===4 || this.status===200

我想将XML数据显示到表中。脚本是:

<script type="text/javascript">

    var xhr= window.XMLHttpRequest? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
    xhr.onreadystatechange= function() {
        if (this.readyState===4 || this.status===200)
            populateTable(this.responseXML);
    };
    xhr.open('GET', 'http://imenicka.cz/xml/menicko.php?hash=fccab45d85b39726611ab433f66263a7&restaurace=430&datum=2013-10-02', true);
    xhr.send();

    function populateTable(xml) {
        var table= document.getElementById('cds');
        var cds= xml.getElementsByTagName('MENICKO');
        for (var i= 0; i<cds.length; i++) {
            var row= table.insertRow(-1);

            function getProperty(name) {
                var el= cds[i].getElementsByTagName(name)[0];
                if (el.firstChild)
                    return el.firstChild.data;
                return ''; // allow empty elements
            }
            function addCell(value) {
                row.insertCell(-1).appendChild(document.createTextNode(value));
            }

            addCell(getProperty('TEXT'));
            addCell(getProperty('CENA'));
        }
    };

</script>
我对javascript知之甚少,所以我无法理解它。

来自http://imenicka.cz/xml/menicko.php?hash=fccab45d85b39726611ab433f66263a7&restaurace=430&datum=2013-10-02的类型为text/html,而不是application/xml

这意味着它未被视为XML和responseXML的响应将为空

您可以通过在此处添加警报来测试这一点:

//...
alert(this.responseXML);
populateTable(this.responseXML);
//...
请参见。

请参见我的答案。。。
//...
alert(this.responseXML);
populateTable(this.responseXML);
//...