慕圣0026647
2018-05-24 02:33
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>Product List: </h1>
<p id="categories"></p >
<p id="products"></p >
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
} };
xhttp.open("GET", "categories.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var txt = "";
x = xmlDoc.getElementsByTagName("Categories")[1];
var categories = get_categories(x);
document.getElementById("categories").innerHTML = categories.nodeName;
document.getElementById("categories").innerHTML = "categories: " + categories.nodeName + " " + categories.firstChild.nodeValue;
return categories;
}
function get_categories(n){
var y = n.firstChild;
while (y.nodeType !=1){
y = y.nextSibling;
}
return y;
}
</script>
<script>
var xhttpx = new XMLHttpRequest();
xhttpx.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200){
myFunction(this);
}
}
xhttpx.open("GET", "products.xml",true);
xhttpx.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var txt = "";
x = xmlDoc.getElementsByTagName("Products")[1];
var products = get_products(x);
document.getElementById("products").innerHTML = products.nodeName;
document.getElementById("products").innerHTML = "products: "+ products.nodeName + " " +products.firstChild.nodeValue;
return products;
}
function get_products(n){
var z = n.lastChild;
while (z.nodeType !=1) {
z = z.previousSibling;
}
return z;
}
</script>
</body>
</html>
两个myFunction冲突了,把第一个改成别的名字
Java眼中的XML---文件读取
83203 学习 · 431 问题
相似问题