-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
37 lines (37 loc) · 1.12 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/index.css">
</head>
<body>
<h1>时钟</h1>
<div id="clock"></div>
</body>
<script>
window.onload = function(){
setInterval(function(){
/**
* 0 对象已建立,但是尚未初始化(尚未调用open方法)
* 1 (初始化) 对象已建立,尚未调用send方法
* 2 (发送数据)send方法已调用,但是当前的状态及http头未知
* 3 (数据传送中) 已接收部分数据
* 4 (完成) 数据接收完毕
*/
//先创建一个ajax对象,负责向服务器端发请求
var xhr = new XMLHttpRequest();
//打开,指定请求的方法和URL
xhr.open('GET','/clock',true);
//指定当你接收到请求之后如何处理
xhr.onreadystatechange = function(){
if(xhr.readyState == 4){
document.querySelector('#clock').innerHTML = xhr.responseText;
}
}
//发服务器端发送请求
xhr.send();
},1000);
}
</script>
</html>