Ajax返回数据的格式
点击蓝字关注秃头程序员(趣图+编程干货+区块链+行业新闻)
xmlDoc=newActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load(txt);
book.xml
<bookstore>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
loadxmldoc.js
function loadXMLDoc(dname)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}
catch(e) {alert(e.message)}
return(xmlDoc);
}
testxml.html
<html>
<head>
<script type="text/javascript" src="loadxmldoc.js"></script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXMLDoc("book.xml");
document.write("xmlDoc is loaded, ready for use");
window.alert(xmlDoc.nodeName);
var x = xmlDoc.getElementsByTagName("title");
window.alert(x);
window.alert(x[0].nodeName);
window.alert(x[0].attributes[0].nodeValue);
window.alert(x[0].childNodes.length);
</script>
</body>
</html>
(免责声明:图文来自网络,若有侵权,请联系秃头程序员后台删除)
往期推荐(点击跳转)
1 |
|
2 |
|
3 |
|
互联网幽默搞笑趣图+编程干货+区块链比特币+行业新闻
长按扫码关注!!!
点亮下方“在看”