forked from donalus/INST377
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax.html
78 lines (61 loc) · 1.34 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<html>
<head>
<style type="text/css">
#square {
margin-top: 20px;
margin-left: 100px;
height: 200px;
width: 200px;
background: orange;
}
div {
margin-bottom: 20px;
}
.round {
border-radius: 20px;
}
#square:hover{
cursor: pointer;
}
</style>
</head>
<body>
<!-- <div id="square" onclick="showSentence()"></div> -->
<div id="square" onclick="trigger()"></div>
<div>
<p> Hello, this is inside a PPPPP tag. </p>
</div>
<script>
// function showSentence(){
// var xhttp = new XMLHttpRequest();
// xhttp.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// document.getElementById("square").innerHTML = this.responseText;
// }
// };
// xhttp.open("GET", "test.txt", true);
// xhttp.send();
// }
function trigger(){
showSentence("json/data.json", test2);
}
function showSentence(url, func){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
func(this);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function test1(xhttps){
document.getElementById("square").innerHTML = xhttps.responseText;
}
function test2(xhttps){
document.getElementById("square").innerHTML = xhttps.responseText;
document.getElementById("square").style.color = "green";
}
</script>
</body>
</html>