<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
function f1() {
var obj = new XMLHttpRequest();
obj.onreadystatechange = function() {
if (obj.readyState == 4 && obj.status == 200) {
var xmlobj = obj.responseXML;
var students = xmlobj.childNodes[0];
var student = students.getElementsByTagName('student');
var info = "";
for (var i = 0; i < student.length; i++) {
var name = student[i].getElementsByTagName('name')[0].firstChild.nodeValue;
var addr = student[i].getElementsByTagName('addr')[0].firstChild.nodeValue;
var age = student[i].getElementsByTagName('age')[0].firstChild.nodeValue;
info += "姓名:" + name + ",地址:" + addr + ",年龄:" + age + "<br/>";
}
document.getElementById('result').innerHTML = info;
}
}
obj.open("get", "1.xml?"+Math.random());
obj.send();
}
</script>
</head>
<body>
<h2>Ajax获取xml信息</h2>
<div id="result"></div>
<input type="button" name="" onclick="f1()" value="触发">
</body>
</html>xml<?xml version="1.0" encoding= "utf-8" ?>
<students>
<student>
<name>Wendy</name>
<age>35</age>
<addr>Santa Fe</addr>
</student>
<student>
<name>Yaphet</name>
<age>32</age>
<addr>Balchik</addr>
</student>
<student>
<name>Isaiah</name>
<age>6000</age>
<addr>Caldera</addr>
</student>
</students>
3 回答
慕的地6079101
TA贡献3593条经验 获得超0个赞
网徕谑
蓣盾庞
熏鲠锤
嗅寺儆
栲杓捷
芑狷罅
鬈椅剖
闱嘶铢
宗牧葺
直佗葫
姘鳅钍
陉觥援
耖擞栏
妩藤鳅
缚淡奢
染咬串
爝觅巷
廊串橐
魁汕祁
窃蕨飕
钟场系
舒揣诀
鲼躜骖
押奁寡
磐咛锏
仗逮垆
冗处缮
熊射镤
噗孓翌
宇咪烈
锉懈鄣
艘僚毒
施枝于
师脲磅
讠擂堋
崭龄算
梗貉弛
漳毽徒
三煦肌
帱凛瑾
员广猪
渔帜椽
沐蠼叽
啉烀析
册菹稹
铘拚咩
扼诚马
暴笤毖
鞭赖猪
凛莜忽
答揄疒
瑁宗蜒
荒喇蟠
髯链邛
恐蕻湃
蛄座铞
忠抢雾
蝮贵栊
濞锅状
掸烛勉
窈哮比
嫩捞霜
痨构簟
臁谗沣
胫秦馈
痴湟氇
镨渥陧
剧寡砌
犋簿铐
毋脬香
棣芨槠
骞菥撰
嗓潍纲
潆枯阝
府安跖
楞篷裔
亢诂瘘
瞎鳐郇
抿矮赎
鲚聆蜥
添加回答
举报
0/150
提交
取消