-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajaxXml2.html
57 lines (51 loc) · 1.67 KB
/
ajaxXml2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ajaxXml2.html</title>
<script>
let cnt=0;
let lnth;
function prev(){
if(cnt>0){
showCD(cnt);
cnt--;
}
}
function next(){
if(cnt<lnth-1){
showCD(cnt);
cnt++;
}
}
function showCD(i){
let xhtp=new XMLHttpRequest();
let myDiv=document.getElementById('show');
let myTag='';
xhtp.onreadystatechange=function(){
if(xhtp.readyState==4 &&xhtp.status==200){
let data=xhtp.responseXML;
let cds=data.getElementsByTagName('CD');
lnth=cds.length;
myTag+='Title: '+cds[i].children[0].innerHTML;
myTag+='<br>Artist: '+cds[i].children[1].innerHTML;
myTag+='<br>Country: '+ cds[i].children[2].innerHTML;
myDiv.innerHTML=myTag;
console.log('title: ('+i+')',cds[i].children[0].innerHTML);
console.log('artist: ',cds[i].children[1].innerHTML);
console.log('country: ',cds[i].children[2].innerHTML);
}
}
xhtp.open('get','cd_catalog.xml');
xhtp.send();
}
</script>
</head>
<body>
<button onclick="showCD(7)">show</button>
<div id="show">정보.</div>
<button onclick="prev()"><<</button>
<button onclick="next()">>></button>
</body>
</html>