오늘 한 일 : 새 글 작성 시 선택한 토픽 데이터 가져가게 하기, 서버에서 데이터 받아와서 뉴스피드 붙이기
더보기
$(document).ready(function () {
show_all_posting()
});
function topic_value_get() {
const topic_values = [];
var topic = $("input[name='topic']:checked");
for (let i = 0; i < topic.length; i++) {
topic_values.push(topic[i].value);
if (topic_values.length > 3) {
alert('토픽은 3개까지 설정 가능합니다.')
return
}
}
let topic_value_join_string = topic_values.join(' ')
console.log(topic_value_join_string)
return topic_value_join_string
}
function new_posting() {
let title = $('#posting_title').val();
let text = $('#posting_text').val();
let topic = topic_value_get()
console.log(topic)
let user = 5
$.ajax({
type: 'POST',
url: '/mypage/newsfeed',
data: {
user_id_give: user,
posting_title_give: title,
posting_text_give: text,
posting_topic_give: topic
},
success: function (response) {
alert(response['msg'])
window.location.reload()
}
})
}
function show_all_posting() {
$.ajax({
type: "GET",
url: "/main",
data: {},
success: function (response) {
let rows = response['posting__box']
console.log(rows)
for (let i = 0; i < rows.length; i++) {
let user_id = rows[i][8]
let user_email = rows[i][10]
let posting_title = rows[i][4]
let user_desc = rows[i][12]
let topic_num_0 = rows[i][16]
let topic_num_1 = rows[i][17]
let topic_num_2 = rows[i][18]
let temp_html = `<div class="newsfeed__newsfeed">
<div class="newsfeed__info">
<a href="#" class="membersCards__list__eachCards newsfeed__writer">
<div class="eachCards__inner-content-wrapper">
<div class="eachCards__avatar"></div>
<div class="eachCards__info">
<div class="eachCards__info__id">${user_id}</div>
<div class="eachCards__info__email">${user_email}</div>
</div>
</div>
</a>
</div>
<button id="open" class="newsfeed__previewCard">
<div class="previewCard__image"></div>
<div class="previewCard__contents">
<div class="previewCard__header">${posting_title}</div>
<div class="previewCard__desc">
${user_desc}
</div>
<div class="previewCard__topics">
<div class="previewCard__topics__tag">${topic_num_0}</div>
<div class="previewCard__topics__tag">${topic_num_1}</div>
<div class="previewCard__topics__tag">${topic_num_2}</div>
</div>
</div>
</button>
</div>`
$('#newsfeed__expansion').append(temp_html)
}
}
}
)
}
오늘은 많은걸 한거 같은데 많은걸 안했다.. 뭐지?
'내일배움캠프 노드 4기 > Today I Learned' 카테고리의 다른 글
22년 12월 08일 TIL (0) | 2022.12.09 |
---|---|
22년 12월 07일 TIL (0) | 2022.12.07 |
22년 12월 05일 TIL (0) | 2022.12.06 |
22년 12월 02일 TIL (0) | 2022.12.03 |
22년 12월 01일 TIL - html (0) | 2022.12.01 |