阅读 Ajax 初学者书籍,第二个示例是从 php 文件中获取 XMl 数据。我已经被困了大约 2 个小时,现在谷歌搜索并阅读该网站对其他人类似问题的答案,我无法弄清楚
我的功能
var options;
function getOptions1(){
var XMLHttpRequestObject = new XMLHttpRequest();
XMLHttpRequestObject.open("GET", "http://localhost/AV/data.php", false); // this was "true" somewhere i read to set it to "false"
XMLHttpRequestObject.onreadystatechange = function(){
if (this.readyState != 4) return;
if (this.status == 200){
alert ("hi");
var xmlDocument = this.responseXML;
options = xmlDocument.getElementsByTagName("option"); // firefox tels me here "TypeError xmlDocument is null"
listOptions();
}
}
XMLHttpRequestObject.send(null);
}
这是data.php文件
<?xml version="1.0" encoding="UTF-8" ?> //i read to add that encoding in there - no help
<options>
<option>red</option>
<option>green</option>
<option>blue</option>
</options>