Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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 XMLHttpRequest.ResponseXML为空_Javascript_Xml_Xmlhttprequest - Fatal编程技术网

Javascript XMLHttpRequest.ResponseXML为空

Javascript XMLHttpRequest.ResponseXML为空,javascript,xml,xmlhttprequest,Javascript,Xml,Xmlhttprequest,我试图从JavaScript代码中访问一个简单的XML文档。但每当我试图找到reponseXML时,它总是导致null。以下是我查找responseXML的代码: function loadXMLDoc(filename){ if (window.XMLHttpRequest){ xhttp=new XMLHttpRequest(); }else{ xhttp=new ActiveXObject("Micro

我试图从JavaScript代码中访问一个简单的XML文档。但每当我试图找到reponseXML时,它总是导致null。以下是我查找responseXML的代码:

    function loadXMLDoc(filename){
        if (window.XMLHttpRequest){
            xhttp=new XMLHttpRequest();
        }else{
            xhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET",filename,false);
        xhttp.send();
        return xhttp.responseXML;
    }
。。。直接复制自。下面是我如何实现它的:

levelDataDoc = loadXMLDoc("worlds.xml");
。。。我三次检查worlds.xml是否在该目录中。但当我安慰它的时候。。它回来了

NULL
如果你一定要看。。。下面是worlds.xml


您必须检查readyState以查看ajax请求是否已完成,它是异步的,您不能只返回。@adeneo-它不是异步的。要打开的第三个参数为false。请查看JavaScript控制台。你看到错误了吗?查看开发人员工具的net选项卡。你看到有人提出要求了吗?“你得到你期望的回应了吗?”昆汀-哦,没有注意到,但是眼神很好。那么它应该是异步的,同步ajax从来都不是一个好主意。
<world>
<width>20</width>
<height>30</height>
<startingX>10</startingX>
<startingY>15</startingY>

<voxelElement1>
    <x>12</x>
    <y>7</y>
    <width>1</width>
    <height>1</height>
    <color>#ffffff</color>
    <imageUrl></imageUrl>
</voxelElemen1t>
</world>