-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00-ajax.html
52 lines (44 loc) · 1.28 KB
/
00-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
45
46
47
48
49
50
51
52
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>
<html lang="en">
<head>
<title>First Ajax</title>
<script language="javascript" type="text/javascript">
var xmlhttp;
function loadDoc() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML = this.responseText;
}
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
function getNum()
{
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = callback;
xmlhttp.open("GET", "00-ajax.php", true);
xmlhttp.send();
}
//When Information comes back from the server
function callback()
{
console.log("Ready State: " + xmlhttp.readyState + "\nStatus" + xmlhttp.status);
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('result').innerHTML = xmlhttp.responseText;
}
}
</script>
</head>
<body>
<div id="result">
</div>
<input type="button" value="Get Random Number" onclick="getNum()"/>
<div id="demo">
<h2>Let AJAX change this text</h2>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>
</body>
</html>