-
Notifications
You must be signed in to change notification settings - Fork 2
/
note.html
139 lines (125 loc) · 5.79 KB
/
note.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>단어장</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
<script>
$(document).ready(function () {
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:8000/note',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "JWT " + localStorage["token"]);
},
success: (result) => {
$("#notes").html("");
for (let i = 0; i < result.results.length; i++) {
const note = result.results[i];
$("#notes").append(
$(`<li class="list-group-item">
${note.title}<br><br>${note.content}<br>${note.member_username}
<button type="button" class="btn btn-primary" onclick="del(${note.id})">삭제</button>
</li>`)
)
}
}
})
})
function signout() {
localStorage.removeItem("token");
location.reload();
}
function del(noteid) {
$.ajax({
type: 'DELETE',
url: 'http://127.0.0.1:8000/note',
data: {
id: noteid,
},
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "JWT " + localStorage["token"]);
},
success: (result) => {
alert("댓글이 삭제되었습니다.")
location.reload();
},
error: (result) => {
console.error(result);
}
})
}
function detailsearch() {
$.ajax({
type: 'GET',
url: `http://127.0.0.1:8000/note/detail?title=${$("#wantword").val()}`,
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "JWT " + localStorage["token"]);
},
success: (result) => {
$("#notes").html("");
console.log(result.results.length);
for (let i = 0; i < result.results.length; i++) {
const note = result.results[i];
$("#notes").append(
$(`<li class="list-group-item">
${note.title}<br><br>${note.content}<br>${note.member_username}
<button type="button" class="btn btn-primary" onclick="del(${note.id})">삭제</button>
</li>`)
)
}
}
})
}
function upload() {
$.ajax({
type: 'POST',
url: 'http://127.0.0.1:8000/note',
data: {
title: $("#uploadtitle").val(),
content: $("#uploadcontent").val(),
},
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "JWT " + localStorage["token"]);
},
success: (result) => {
alert("단어가 저장되었습니다.")
location.reload();
},
error: (result) => {
console.error(result);
}
})
}
</script>
<style>
main {
margin: 0 auto;
max-width: 375px;
}
</style>
</head>
<body>
<main>
<div class="container">
<ul class="list-group list-group-flush" id="notes">
</ul>
<div class="text-right">
<input type="text" placeholder="원하는 단어 검색" id="wantword">
<button type="button" class="btn btn-primary" onclick="detailsearch()">검색</button>
</div>
<div class="text-right">
<button type="button" class="btn btn-primary" onclick="signout()">로그아웃</button>
</div>
<div class="text-right">
<input type="text" placeholder="단어 입력" id="uploadtitle">
<input type="text" placeholder="단어 뜻 입력" id="uploadcontent">
<button type="button" class="btn btn-primary" onclick="upload()">단어저장</button>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>