-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest03.html
31 lines (26 loc) · 914 Bytes
/
test03.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
<meta charset="utf-8">
<button id="btn">Pozdrav</button>
<div id="result" style="border: solid 2px red;"></div>
<script>
window.onload = function() {
var button = document.getElementById("btn");
btn.onclick = function() {
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
console.log("State: " + xhr.readyState);
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
var osoba = xhr.responseXML;
var result = document.getElementById("result");
result.innerHTML = "Jméno je " + osoba.getElementsByTagName("jmeno").item(0).textContent
+ " a věk je " + osoba.getElementsByTagName("vek").item(0).textContent;
} else {
alert("Server error: " + xhr.status);
}
}
}
xhr.open("GET", "http://localhost:8000/data.xml");
xhr.send();
};
}
</script>