学习下Ajax 不会用responseXML 请教下
XML文件<?xml version="1.0" encoding="utf-8" ?>
<People>
<Name>张三</Name>
<Age>18</Age>
</People>
<People>
<Name>李四</Name>
<Age>19</Age>
</People>
<People>
<Name>王二</Name>
<Age>20</Age>
</People>
能给个以responseXML方式读取这个XML的例子吗,感激不尽啊~
XML文件<?xml version="1.0" encoding="utf-8" ?>
<People>
<Name>张三</Name>
<Age>18</Age>
</People>
<People>
<Name>李四</Name>
<Age>19</Age>
</People>
<People>
<Name>王二</Name>
<Age>20</Age>
</People>
能给个以responseXML方式读取这个XML的例子吗,感激不尽啊~
解决方案 »
- 调用JS弹出窗口插件,原页面没有问题,放到框架页内路径错误,各位大侠帮帮忙
- 我真没分啊 跪求啊
- jquery ajax返回的数据,如何提取html?
- 急!!!!!!!!!js 画圆问题
- th.onclick出现未定义
- 用javascript实现树
- 一个没有数据库的空间怎么做动态网站?
- JavaScript中请问如何将变量放入正则表达式中?比如var str = /.22X22/;中我想让X是从变量传进来的字符串,请问应该如何写?
- 超难问题!!!!!!帮忙!!在线等立刻给分!!!!!!!!
- [求助帖]萌新求助,router-view渲染不出来
- 急急急,问个javascript按钮链接的问题?
- jquery多文件间调用问题
<?xml version="1.0" encoding="utf-8"?>
<test>
<People>
<Name>张三</Name>
<Age>18</Age>
</People>
<People>
<Name>李四</Name>
<Age>19</Age>
</People>
<People>
<Name>王二</Name>
<Age>20</Age>
</People>
</test><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script type="text/javascript">
var ajax = (function(){
function creatXHR(){
if (window.ActiveXObject) return new window.ActiveXObject('Microsoft.XMLHTTP');
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
return function(url, fn){
var xhr = creatXHR();
xhr.open('GET', url, true);
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
fn(xhr);
}
}
xhr.send(null);
return xhr;
}
})(); var test = ajax('xml.xml', function(xhr){
if (xhr && xhr.responseXML) {
var names = [], nodes = xhr.responseXML.getElementsByTagName('Name');
if (nodes) {
for (var i = 0; i < nodes.length; i++) {
names.push(nodes[i].childNodes[0].data);
}
alert(names.join(', '));
}
}
});
</script>
</head>
<body>
</body>
</html>
var xmlHttp;
function CreateXMLHttpRequest()
{
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}function SubGet()
{
if (xmlHttp.readyState==4)
{
//var node = xmlHttp.responseXML.getElementsByTagName('WebTitle');
var a = xmlHttp.responseXML.getElementsByTagName('WebTitle');alert(a[0].childNodes[0].data);
}
}
function Fuck()
{
CreateXMLHttpRequest();
if (xmlHttp!=null)
{
xmlHttp.open("get","xml.xml",true);
xmlHttp.onreadystatechange = SubGet;
xmlHttp.send(null);
}
}为何无法获取呢? XML文件 <?xml version="1.0" encoding="utf-8" ?>
<Web>
<Config>
<WebTitle>标题</WebTitle>
</Config>
</Web>我都快崩溃了~