为了账号安全,请及时绑定邮箱和手机立即绑定

怎样把两个xml文件都在一个html网页上显示出来呢?我写的只会执行最后一个。

<!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>

正在回答

1 回答

两个myFunction冲突了,把第一个改成别的名字

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

怎样把两个xml文件都在一个html网页上显示出来呢?我写的只会执行最后一个。

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信