-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample_ajax.html
44 lines (42 loc) · 1.37 KB
/
Example_ajax.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ajax example</title>
</head>
<body>
<button onclick="onld('Empdetails.xml',func)">Get details</button>
<button onclick="onld('cd_catalog.xml',func1)">get text</button>
<div id="demo"></div>
<script>
function onld(url,cfunc) {
var xhttp= new XMLHttpRequest();
xhttp.onreadystatechange=function () {
if(this.readyState==4&&this.status==200){
console.log("in if");
cfunc(this);
}
};
xhttp.open('get',url,true);
xhttp.send();
}
function func(xhttp) {
var xmldoc,x,i, text;
xmldoc=xhttp.responseXML;
console.log(xmldoc);
text="";
x=xmldoc.getElementsByTagName("name");
for(i=0;i<x.length;i++){
console.log(i);
text+=x[i].childNodes[0].nodeValue+"<br />";
}
console.log(text);
document.getElementById('demo').innerHTML=text;
}
function func1(xhttp) {
var str=xhttp.responseText;
document.getElementById("demo").innerHTML=str;
}
</script>
</body>
</html>