<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Ajax로 Web API의 JSON 데이터 출력하기 코드 샘플</title>
<script src="../Scripts/jquery-2.1.3.min.js"></script>
<script>
$(function () {
$.ajax({
url: "/api/divisions",
dataType: "json",
success: function (data) {
// this로 출력
$.each(data, function () {
$("#lstDivisions").append(
"<tr><td>" + this.DivisionId + "</td><td>" +
this.DivisionName + "</td><td>" + this["DivisionNameEng"] + "</td></tr>");
});
// 매개변수로 출력
$.each(data, function (index, entry) {
$("#lstDivisions").append(
"<tr><td>" + entry.DivisionId + "</td><td>" +
this.DivisionName + "</td><td>" + entry["DivisionNameEng"] + "</td></tr>");
});
},
error: function () {
console.log("에러 발생");
}
});
});
</script>
</head>
<body>
<table id="lstDivisions" border="1"></table>
</body>
</html>