[jQuery] $.getJSON 으로 JSON 출력하기
- 📕 Programing/jQuery
- 2020. 5. 12. 14:27
$.getJSON 사용법
index.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.getJSON('/json', function(data){
//JSON을 순회화여 출력한다
$.each(data, function(index, obj){
$('body').append('<h1>' + obj.id + ' : ' + obj.name + '</h1>');
})
});
});
</script>
<body>
</body>
</html>
JSON파일( person.json )
[
{
"id": "1",
"name": "Tiger Nixon"
},
{
"id": "2",
"name": "joy"
},
{
"id": "3",
"name": "young"
}
]
'📕 Programing > jQuery' 카테고리의 다른 글
[jQuery] 해당 요소의 상위요소 탐색 (0) | 2021.10.13 |
---|---|
[jQuery] 테이블의 선택한 열 값 가져오는 방법 (0) | 2021.08.24 |
[jQuery] selecbox option값 자동 체크 (0) | 2020.05.25 |
$.ajax 을 활용한 JSON 파싱 (0) | 2020.05.13 |
[jQuery] Document.ready , onload 실행 순서 (0) | 2020.05.11 |