index1.html
Insert title herewindow.onload = function(){
var anodes = document.getElementsByTagName("a");
for(var i = 0; i
anodes[i].onclick = function(){
var request = new XMLHttpRequest();
var method = "GET";
var url = this.href;
request.open(method,url);
request.send(null);
request.onreadystatechange = function(){
if(request.readyState == 4){
if(request.status == 200||request.status == 304){
//1.结果为XML格式,所以需要使用responseXML来获取
var result = request.responseXML;
//结果不能直接用,必须先创建对应的节点,再把节点加到#details去;
var name = result.getElementsByTagName("name")[0].firstChild.nodeValue;
var website = result.getElementsByTagName("website")[0].firstChild.nodeValue;
var email = result.getElementsByTagName("email")[0].firstChild.nodeValue;
//alert(name);
//alert(website);
//alert(email);
var anode = document.createElement("a");
anode.appendChild(document.createTextNode(name));
anode.href = "taobao" + email;
var h2node = document.createElement("h2");
h2node.appendChild(anode);
var anode2 = document.createElement("a");
anode2.appendChild(document.createTextNode(website));
anode2.href = "taobao" + website;
var detailnode = document.getElementById("details");
detailnode.innerHTML="";
detailnode.appendChild(h2node);
detailnode.appendChild(anode2);
}
}
}
return false;
}
}
}
1.xml
Andy
https://www.taobao.com/
https://mail.163.com/
2.xml
siri
https://www.w3school.com.cn/
https://mail.163.com/
结果截图
标签:XML,xml,www,ajax,mail.163,https,var,数据格式,com
来源: https://www.cnblogs.com/a155-/p/12450358.html