-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax-blog.html
More file actions
122 lines (111 loc) · 4.19 KB
/
ajax-blog.html
File metadata and controls
122 lines (111 loc) · 4.19 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Gayathri:wght@100;400;700&display=swap" rel="stylesheet">
<style>
* {
font-family: 'Gayathri', sans-serif;
font-weight: bold;
}
body {
background-image: url("image/sakura.png");
background-repeat: repeat;
position: relative;
margin-top: 0;
padding-top: 2em;
}
body::before {
z-index: -1000;
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: rgba(255, 255, 255, 0.1);
}
#h1_1 {
font-size: 3rem;
}
h5 {
font-size: 1.5em !important;
}
h6, h5 {
font-weight: 100 !important;
}
p::first-letter {
font-size: 150%;
}
#btn {
background-color: lightsalmon;
border: none;
}
hr {
border: 1px dotted lightsalmon;
}
</style>
<title>Test Page</title>
</head>
<body>
<div class="container">
<h1 id="h1_1">My Blog</h1>
<!-- <div id="posts"></div>-->
<ul class="list-unstyled" id="posts"></ul>
<div class="text-center pb-3">
<button id="btn" class="btn btn-secondary w-50">refresh</button>
</div>
</div>
<script src="js/jquery-3.5.1.js"></script>
<script>
(function () {
"use strict"
$().ready(function () {
$.ajax("data/blog.json").done(onSuccess);
function onSuccess(data, status, jqXhr) {
console.log("AJAX call completed successfully!");
console.log("Request status: " + status);
console.log("Data returned from server:", data);
let html = '';
for (let dataItem of data) {
// html += `<div>
// <div>${dataItem['title']}</div>
// <div>${dataItem.date}</div>
// <div>categories: ${dataItem.categories}</div>
// <div>${dataItem.content}</div>
// </div><hr>`;
html += `
<li class="media">
<img src="https://picsum.photos/120/120?random=${dataItem.id}" class="mr-3">
<div class="media-body">
<h5 class="mt-0 mb-1 font-weight-bolder">${dataItem['title']}</h5>
<h6 class="mt-0 mb-1 font-italic">${dataItem['date']}</h6>
<div class="mb-1 font-italic">categories: ${dataItem.categories}</div>
<p>${dataItem.content}</p>
</div>
</li><hr>
`;
console.log(dataItem);
}
$('#posts').html(html);
}
$('#btn').click(function () {
$.ajax("data/blog.json").done(onSuccess);
})
});
})();
</script>
<script src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkf"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
crossorigin="anonymous"></script>
</body>
</html>