배열로 답긴 값 json 형태로 변경하는 키워드
const orderToJson = JSON.stringify(orderData);
fetch : post로 보내기
fetch('컨트롤러 맵핑 주소', {
method: 'POST',
headers : {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: orderToJson,
}).then(response => response.text())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
fetch : get으로 보내고 json로 받기
fetch('/order/getList?tblNo='+tableNum)
.then(response => response.json())
.then(data => {
const detailsContainer = document.querySelector('.details ul');
detailsContainer.innerHTML = '';
data.forEach(ord => {
const listItem = document.createElement('li');
<div class="li-inner">
<p class="total">${new Intl.NumberFormat('ko-KR').format(ord.orderTotalPrice)}원</p>
</div>
`;
detailsContainer.appendChild(listItem);
});
})
.catch(error => {
console.error('Error:', error);
});
}