-
Notifications
You must be signed in to change notification settings - Fork 50
/
demo3.html
90 lines (86 loc) · 1.72 KB
/
demo3.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
85
86
87
88
89
90
<!DOCTYPE html>
<html>
<head>
<title>demo3</title>
<meta charset="utf-8">
<style type="text/css">
* {
text-align: center;
}
.box {
border: 1px solid #ccc;
padding: 10px;
margin: 10px;
}
.box:hover {
background-color: green;
}
.btn {
border: 1px solid #e27272;
border-radius: 2px;
color: #e27272;
padding: 10px;
margin: 10px;
display: inline-block;
cursor: pointer;
width: 64px;
height: 18px;
text-align: center;
}
.btn img {
width: 18px;
}
</style>
</head>
<body>
<div class="ct">
<div class="box">内容1</div>
<div class="box">内容2</div>
</div>
<a class="btn">加载更多</a>
<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.js
"></script>
<script type="text/javascript">
$(".btn").on("click", function(){
var $this = $(this);
console.log($this);
var nowLength = $(".ct").children().size();
console.log(nowLength);
if($(this).data("isLoading")){
return;
}
$this.data("isLoading", true).html('<img src="loading.gif">');
$.ajax({
url: "demo3.php",
dataType: "json",
type: "get",
data: {
start: (nowLength+1),
len: 6
},
success: function(json){
onSuccess(json);
},
error: function(){
onError();
}
});
function onSuccess(json){
if (json.status === 1){
for(var i=0;i<json.data.length;i++){
$(".ct").append('<div class="box">' + json.data[i] + '</div>');
}
$this.data("isLoading", false).text("加载更多");
} else {
$this.data("isLoading", false).text('加载更多');
alert("加载失败,服务器原因");
}
}
function onError(){
$this.data("isLoading", false).text('加载更多');
alert("加载失败,网络原因");
}
})
</script>
</body>
</html>