(기초)그래서 뭘 배운거야?/JSON
JSON-01-getJSON
Soheny.P
2021. 10. 19. 16:31
728x90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="/JS/jquery-3.6.0.min.js"></script>
<style>
</style>
</head>
<body>
<!-- JSON : 데이터 저장, 전송을 위한 텍스트 형식으로 JS의 확장으로 만들어짐 > JS의 객체 표기법을 따름 >> 데이터 텍스트만 가지고 있음 -->
<!-- getJSON으로 비동기 통신해 데이터 받아오기 -->
<div></div>
<button>요청</button>
<script>
$(function () {
$("button").click(function(){
$.getJSON("01-json_demo_text.json", function(result){
$.each(result, function(i, field){
$("div").append(field+" ");
})
});
});
});
</script>
</body>
</html>
{
"name" : "Soheny",
"age" : 31,
"address" : "지구"
}
728x90