请问用ajax如何得到xml节点值
请问下面的代码,如何得到books.xml里的值,谢谢
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function ajax(url, fnSucc, fnFaild)
{
//1.创建ajax对象
var oAjax=null;
if(window.XMLHttpRequest)
{
oAjax=new XMLHttpRequest();
}
else
{
oAjax=new ActiveXObject("Microsoft.XMLHTTP");
}
oAjax.open('GET', url, true);
oAjax.send();
oAjax.onreadystatechange=function ()
{
if(oAjax.readyState==4)
{
if(oAjax.status==200)
{
fnSucc(oAjax.responseText);
}
else
{
if(fnFaild)
{
fnFaild();
}
}
}
};
}
</script>
<script>
window.onload=function ()
{
ajax('books.xml',function (str)
{
alert("如何得到xml值如Lee或hhh")
}
)
}
</script>
</head>
<body>
</body>
</html>
XML Ajax
<root>
<user>Lee</user>
<email>yc</email>
<url>http://www.baidu.com</url>
</root>
<root>
<user>ddd</user>
<email>hhh</email>
<url>http://www.baidu.com</url>
</root>
<roots><root>
<user>Lee</user>
<email>yc</email>
<url>http://www.baidu.com</url>
</root>
<root>
<user>ddd</user>
<email>hhh</email>
<url>http://www.baidu.com</url>
</root></roots>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function ajax(url, fnSucc, fnFaild) {
//1.创建ajax对象
var oAjax = null;
if (window.XMLHttpRequest) {
oAjax = new XMLHttpRequest();
}
else {
oAjax = new ActiveXObject("Microsoft.XMLHTTP");
}
oAjax.open('GET', url, true);
oAjax.send();
oAjax.onreadystatechange = function () {
if (oAjax.readyState == 4) {
if (0 == oAjax.status
[解决办法]
oAjax.status == 200) {
//fnSucc(oAjax.responseText);
fnSucc(oAjax.responseXML);//////////////////////
}
else {
if (fnFaild) {
fnFaild();
}
}
}
};
}
</script>
<script>
window.onload = function () {
ajax('books.xml', function (dom) {//////////////////////
var user = dom.getElementsByTagName('user');
for(var i=0;i<user.length;i++)alert(user[i].firstChild.nodeValue)
}, function () { alert('fail') }
)
}
</script>
</head>
<body>
</body>
</html>