【发布时间】:2012-12-30 11:14:55
【问题描述】:
我想从 XML 文件获取数据到 JS 变量(我想使用纯 JS,不使用 jQuery)。但是我在下载文件时总是出错:
var url = "http://www.w3schools.com/xml/note.xml";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function(event){ processRequest(event,xmlhttp); };
xmlhttp.send();
function processRequest(event,xmlhttp) {
if(xmlhttp.readyState != 4) return;
alert("status: " +xmlhttp.status);
}
响应 xml 始终为空 - 响应状态为 0。
【问题讨论】: