메시지 브릿지

매뉴얼 [웹] 기본 서버에서 받은 소스 설명

페이지 정보

본문

updateDisplay() 내 postData의 역할 & 활용 설명


updateDisplay() 안에서 만들어지는 postData는
서버(WebSocket)에서 받은 메시지를 프론트에서 활용하기 좋은 ‘가공용 데이터 꾸러미’로 만들어둔 것입니다.


const postData = {
    type: lastMessage.type,
    auth : lastMessage.auth,
    mb_id: MB_ID,
    write_id : lastMessage.write_id,
    ip: USER_IP,
    noti_type: lastMessage.noti_type,
    mb_name: lastMessage.mb_name,
    bo_table: lastMessage.bo_table,
    bo_subject: lastMessage.bo_subject,
    wr_subject: lastMessage.wr_subject,
    wr_id: lastMessage.wr_id,
    skin_url: lastMessage.skin_url
};


여기까지는 ‘준비’ 단계입니다.
이후에는 원하는 대로 가공해서 무엇이든 할 수 있어요.


postData로 할 수 있는 일

이 postData는 말 그대로 만능 재료입니다.
필요한 요리를 자유롭게 선택하면 됩니다.


1) alert()으로 바로 출력

alert(postData.wr_subject);
alert(JSON.stringify(postData, null, 2));


바로 경고창에 띄워 확인하거나 디버깅용으로 사용할 수 있습니다.


2) AJAX로 서버에 다시 전송


jQuery 예시

$.ajax({
    url: "/notification/save.php",
    type: "POST",
    data: postData,
    success: function(res){
        console.log("저장 완료:", res);
    }
});

 

fetch 예시

fetch('/notification/save.php', {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(postData)
});


데이터베이스에 저장하거나 로그 파일로 기록할 때 사용합니다.


3) 폼 POST 전송


만약 서버가 form 방식만 받는다면:

const form = document.createElement("form");
form.method = "POST";
form.action = "/noti";

for (const key in postData) {
    const input = document.createElement("input");
    input.type = "hidden";
    input.name = key;
    input.value = postData[key];
    form.appendChild(input);
}

document.body.appendChild(form);
form.submit();


전통적인 POST 방식도 문제없이 지원합니다.


4) HTML UI에 표시

document.querySelector("#notiTitle").textContent = postData.wr_subject;
document.querySelector("#notiWriter").textContent = postData.mb_name;
document.querySelector("#notiBoard").textContent = postData.bo_subject;


알림 팝업 / 모달 / UI 카드 등 원하는 곳에 값을 끼워 넣기만 하면 됩니다.


5) 다른 JS 함수에 전달해서 처리

sendToPopup(postData);
logNotification(postData);
updateCounter(postData);


정리된 JSON 데이터를 다른 기능으로 넘겨 확장할 수도 있습니다.

댓글목록

등록된 댓글이 없습니다.

메시지 브릿지

Total 19건 1 페이지
  • RSS
공지 공지

관리자 · 조회 2645 · 날짜 2025-11-13 15:27:10
공지 설명

관리자 · 조회 2937 · 날짜 2025-11-09 14:35:01

관리자 · 조회 1483 · 날짜 2025-12-09 08:37:25

관리자 · 조회 1628 · 날짜 2025-12-05 15:42:49

관리자 · 조회 1669 · 날짜 2025-12-03 08:49:25
열람중 매뉴얼

관리자 · 조회 1642 · 날짜 2025-12-02 17:53:38

관리자 · 조회 1641 · 날짜 2025-12-02 08:31:07

관리자 · 조회 1599 · 날짜 2025-12-01 23:03:40

관리자 · 조회 1757 · 날짜 2025-11-29 22:07:08

관리자 · 조회 1639 · 날짜 2025-11-29 18:11:30

관리자 · 조회 1855 · 날짜 2025-11-23 22:36:55

관리자 · 조회 2059 · 날짜 2025-11-20 09:54:24

관리자 · 조회 2226 · 날짜 2025-11-15 20:02:01

관리자 · 조회 2210 · 날짜 2025-11-14 10:28:40

관리자 · 조회 2449 · 날짜 2025-11-14 06:49:26

검색

© 2025 Designonex. All rights reserved. · 이용약관 · 개인정보 처리방침