forked from myeong/INST377
-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathajax.html
executable file
·84 lines (68 loc) · 1.52 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
79
80
81
82
83
84
<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();
showSentence("json/data.json", test1);
}
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;
//var data = eval(xhttps.responseText);
var data = JSON.parse(xhttps.responseText);
//eval("alert('BOO! I could be bad!')");
alert("Response has " + data.length + " entries.")
}
function test2(xhttps){
document.getElementById("square").innerHTML = xhttps.responseText;
document.getElementById("square").style.color = "green";
}
</script>
</body>
</html>