-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory_ajax.html
55 lines (48 loc) · 1.57 KB
/
history_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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>HISTORY</h1>
<button id="trigger">CHANGE HASH</button>
<br/>
<div class="dynamic"></div>
<script>module = {};</script>
<script src="js/jquery1.91.min.js"></script>
<script src="./js/md5.js"></script>
<script src="js/asdui.js"></script>
<script>
!function(){
/* emulate outer usage */
/* test data */
var HASHLIST = [1,2,3,4];
var index = -1;
function callback(hash) {
var params = "?app=news&act=articles&model=normal&country=jp&type="+hash+"&num=10";
$.ajax({
url: "http://api.ghk.hao123.com/" + params,
dataType: "jsonp",
jsonp: "jsonp",
jsonpCallback: "ghao123_" + hex_md5(params,16)
}).done(function(data){
$(".dynamic").html(JSON.stringify(data.content.data.contents[hash]));
});
}
// init a history instance
var historyObj =new ZUI.History();
$("#trigger").click(function() {
index == 3 ? index = 0 : index++;
var newHash = HASHLIST[index];
// bind trigger
historyObj.pushState(newHash);
});
// capture history custom event
$(historyObj).on("popstate", function(e, hash) {
callback(hash);
});
}();
</script>
</body>
</html>