String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
My JSP 'index.jsp' starting pagefunction loadXMLDoc(url) {
var xmlhttp;
var txt,xx,x,i;
xmlhttp=getXhr();
try {
xmlhttp.open("post",url,true);
} catch (er) {
alert("ad" + er);
}
xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
txt = "
Title | Artist | Person |
---|
x = xmlhttp.responseXML.documentElement
.getElementsByTagName("CD");
for (i = 0; i < x.length; i++) {
txt = txt + "
";xx = x[i].getElementsByTagName("TITLE");
{
try {
txt = txt + "
" + xx[0].firstChild.nodeValue+ "
";} catch (er) {
txt = txt + "
";}
}
xx = x[i].getElementsByTagName("ARTIST");
{
try {
txt = txt + "
" + xx[0].firstChild.nodeValue+ "
";} catch (er) {
txt = txt + "
";}
}
xx = x[i].getElementsByTagName("PERSON");
{
try {
txt = txt + "
" + xx[0].getElementsByTagName("ID")[0].firstChild.nodeValue+"/"+ xx[0].getElementsByTagName("NAME")[0].firstChild.nodeValue+ "
";} catch (er) {
txt = txt + "
";}
}
txt = txt + "
";}
txt = txt + "
";document.getElementById('txtCDInfo').innerHTML = txt;
}
};
xmlhttp.send();
}
获得 CD信息
AjaxLoadXmlRes.xml
Empire BurlesqueBob Dylan
USA
Columbia
10.90
1985
1
张三
Hide your heartBonnie Tyler
UK
CBS Records
9.90
1988
2
李四
Greatest HitsDolly Parton
USA
RCA
9.90
1982
3
王五
Still got the bluesGary Moore
UK
Virgin records
10.20
1990
ErosEros Ramazzotti
EU
BMG
9.90
1997
4
绝世好剑
One night onlyBee Gees
UK
Polydor
10.90
1998
Sylvias MotherDr.Hook
UK
CBS
8.10
1973
Maggie MayRod Stewart
UK
Pickwick
8.50
1990
RomanzaAndrea Bocelli
EU
Polydor
10.80
1996
When a man loves a womanPercy Sledge
USA
Atlantic
8.70
1987
Black angelSavage Rose
EU
Mega
10.90
1995
1999 Grammy NomineesMany
USA
Grammy
10.20
1999
For the good timesKenny Rogers
UK
Mucik Master
8.70
1995
Big Willie styleWill Smith
USA
Columbia
9.90
1997
Tupelo HoneyVan Morrison
UK
Polydor
8.20
1971
The very best ofCat Stevens
UK
Island
8.90
1990
StopSam Brown
UK
A and M
8.90
1988
Bridge of SpiesT'Pau
UK
Siren
7.90
1987
Private DancerTina Turner
UK
Capitol
8.90
1983
Midt om nattenKim Larsen
EU
Medley
7.80
1983
Pavarotti Gala ConcertLuciano Pavarotti
UK
DECCA
9.90
1991
The dock of the bayOtis Redding
USA
Atlantic
7.90
1987
Picture bookSimply Red
EU
Elektra
7.20
1985
RedThe Communards
UK
London
7.80
1987
Unchain my heartJoe Cocker
USA
EMI
8.20
1987
init.js
function getXhr() {
var xhr = null;
try {
xhr = new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
return xhr;
}
总结
以上是编程之家为你收集整理的Ajax动态加载xml文件内容全部内容,希望文章能够帮你解决Ajax动态加载xml文件内容所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。