ajax修改内容xml内容,Ajax动态加载xml文件内容

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%>

My JSP 'index.jsp' starting page

function 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 = "

TitleArtistPerson

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 Burlesque

Bob Dylan

USA

Columbia

10.90

1985

1

张三

Hide your heart

Bonnie Tyler

UK

CBS Records

9.90

1988

2

李四

Greatest Hits

Dolly Parton

USA

RCA

9.90

1982

3

王五

Still got the blues

Gary Moore

UK

Virgin records

10.20

1990

Eros

Eros Ramazzotti

EU

BMG

9.90

1997

4

绝世好剑

One night only

Bee Gees

UK

Polydor

10.90

1998

Sylvias Mother

Dr.Hook

UK

CBS

8.10

1973

Maggie May

Rod Stewart

UK

Pickwick

8.50

1990

Romanza

Andrea Bocelli

EU

Polydor

10.80

1996

When a man loves a woman

Percy Sledge

USA

Atlantic

8.70

1987

Black angel

Savage Rose

EU

Mega

10.90

1995

1999 Grammy Nominees

Many

USA

Grammy

10.20

1999

For the good times

Kenny Rogers

UK

Mucik Master

8.70

1995

Big Willie style

Will Smith

USA

Columbia

9.90

1997

Tupelo Honey

Van Morrison

UK

Polydor

8.20

1971

The very best of

Cat Stevens

UK

Island

8.90

1990

Stop

Sam Brown

UK

A and M

8.90

1988

Bridge of Spies

T'Pau

UK

Siren

7.90

1987

Private Dancer

Tina Turner

UK

Capitol

8.90

1983

Midt om natten

Kim Larsen

EU

Medley

7.80

1983

Pavarotti Gala Concert

Luciano Pavarotti

UK

DECCA

9.90

1991

The dock of the bay

Otis Redding

USA

Atlantic

7.90

1987

Picture book

Simply Red

EU

Elektra

7.20

1985

Red

The Communards

UK

London

7.80

1987

Unchain my heart

Joe 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;

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值