{
<c:choose>
<c:when test="${ not empty soldCount }">
"status":true,
"totals":{
"boardsSold":${soldCount[0]},
"bootsSold":${soldCount[1]},
"bindingsSold":${soldCount[2]},
}
</c:when>
<c:otherwise>
"status":false
</c:otherwise>
</c:choose>
}
제이슨을 이렇게 만들어주고 이걸 아약스로 읽어오면 된다.
function getNewTotals() {
$.getJSON("getUpdatedBoardSales-ajax-db2.jsp",updatePage);
}
function updatePage(jsonObj) {
if(!jsonObj.status){
alert("데이터 조회 실패")
return;
}
var boardsSold=jsonObj.totals.boardsSold;
var bootsSold=jsonObj.totals.bootsSold;
var bindingsSold=jsonObj.totals.bindingsSold;
var cash=0;
$("#boards-sold").text(boardsSold);
var boardsCash=($("#boards-price").text()-$("#boards-cost").text());
cash+=boardsCash;
$("#boots-sold").text(bootsSold);
var bootsCash=($("#boots-price").text()-$("#boots-cost").text());
cash+=bootsCash;
$("#bindings-sold").text(bindingsSold);
var bindingsCash=($("#bindings-price").text()-$("#bindings-cost").text());
cash+=bindingsCash;
$("#cash").text(Math.round(cash * 100) / 100);
}