-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
51 lines (37 loc) · 978 Bytes
/
example.html
File metadata and controls
51 lines (37 loc) · 978 Bytes
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
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Server Time</title>
<link href="http://bit.ly/GPvP5H" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Server Time</h1>
<div id="mainContent">
<p id="time">?</p>
<button id="clickButton" class="buttonStyle">
show time</button>
</div>
<script>
var myButton = document.getElementById("clickButton");
var myText = document.getElementById("time");
myButton.addEventListener('click', getServerTime, false)
function getServerTime() {
var request = new XMLHttpRequest();
var url = "servertime.php";
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
if(request.readyState == 4 && request.status == 200) {
showTime(request.responseText);
}
}
request.send();
}
function showTime(response) {
var time = JSON.parse(response);
myText.textContent = time;
}
</script>
</body>
</html>