스파르타 코딩클럽 4주차 숙제 '팬명록 실습'
실습으로 작성한 블랙핑크 팬명록에 닉네임과, 코멘트를 남기면 몽고 DB에 저장하고 저장된 데이터를 페이지에 불러와서 뿌려주는 기능을 구현
function save_comment() {
let name = $('#name').val()
let comment = $('#comment').val()
$.ajax({
type: 'POST',
url: '/homework',
data: { name_give: name, comment_give: comment },
success: function (response) {
alert(response['msg'])
window.location.reload()
}
})
}
function show_comment() {
$.ajax({
type: "GET",
url: "/homework",
data: {},
success: function (response) {
let rows = response['fighting']
for (let i = 0; i < rows.length; i++) {
let name = rows[i]['name']
let comment = rows[i]['comment']
let temp_html = `<div class="card">
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>${comment}</p>
<footer class="blockquote-footer">${name}</footer>
</blockquote>
</div>
</div>`
$('#comment-list').append(temp_html)
}
}
});