
몽고디비에도 3개의 댓글이 있는데 연결이 잘못된건지 덧글입력과 기존것들이 안보입니다.
index.html 코드
<script>
$(document).ready(function(){
set_temp()
show_comment()
});
function set_temp(){
$.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/weather/seoul",
data: {},
success: function (response) {
$('#temp').text(response['temp'])
}
})
}
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['comments']
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>${name}</p>
<footer class="blockquote-footer">${comment}</footer>
</blockquote>
</div>
</div>`
$('#comment-list').append(temp_html)
}
}
});
}
</script>

