Javascript XMLHTTPRequest没有返回结果

时间:2019-02-25 02:34:43

标签: xmlhttprequest

我无法获取“ this.responseXML”来提供任何内容。 我使用alert()进行调试。我运行了脚本,看到警报“ A”,“ C”,“ A”,“ C”,“ A”,然后完成,但是从屏幕上没有看到从httprequest检索到的任何内容。警报“ B”从未显示。 但是,如果您浏览该API,则会看到返回的XML数据:http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=ttc&r=42&t=0

需要帮助。 谢谢

<html>
<body>
<h2>Using the XMLHttpRequest Objectx</h2>

<div id="demo">
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</div>

<script>
function loadXMLDoc() {
    var xhttp = new XMLHttpRequest();

    xhttp.onreadystatechange = function() {
        alert("A");
        if (this.readyState == 4 && this.status ==200) {
            alert("B");
            document.getElementById("demo").innerHTML = this.responseXML;      
        }
        else
          alert("C");
};  
xhttp.open("GET", "http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=ttc&r=42&t=0", true);
xhttp.send();
}
</script>

</body>
</html>

0 个答案:

没有答案