-
Notifications
You must be signed in to change notification settings - Fork 7
/
index_cache.html
50 lines (47 loc) · 1.14 KB
/
index_cache.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SSE技术</title>
</head>
<body>
<div>
<strong>测试缓存更新,对在线用户推送更新</strong>
<button onclick="testCache_click()">
测试按钮,本地localStory混存dom更新
</button>
<div id="domUpdate"></div>
</div>
<!--<iframe src="www.baidu.com"></iframe>-->
</body>
</html>
<script src='SSE.js'></script>
<script src='ajax.1.7.js'></script>
<script>
(function () {
localStorage.setItem('dom','我是基础缓存哦')
})()
// 测试的单机事件
function testCache_click() {
var dom_t = localStorage.getItem('dom')
var node_id = document.querySelector('#domUpdate')
node_id.innerHTML = dom_t
}
// 建立远程连接
SSE.create({
url:'http://localhost:8076',
data:{ name:'cache' },
openEvent:function (res) {
console.log('开启事件')
console.log(res)
},
messageEvent:function(res){
// 接受数据,更新缓存
localStorage.setItem('dom',res.data)
},
errorEvent:function(res){
console.log('错误事件')
console.log(res)
}
})
</script>