<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>JQuery 연습하고 가기!</title>
<!-- JQuery를 import 합니다 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style type="text/css">
div.question-box {
margin: 10px 0 20px 0;
}
div.question-box > div {
margin-top: 30px;
}
</style>
<script>
function q1() {
var url = 'http://api.kcisa.kr/openapi/service/rest/meta10/get20150059'; /*URL*/
var queryParams = {
'serviceKey': 'af25d177-e08f-4a2c-bd85-61b8b81396d4',
'numOfRows': '10',
'pageNo': '1'
};
$.ajax({
url: url,
data: queryParams,
type: "GET",
dataType: "xml",
success: function(response) {
console.log('status: ' + this.status);
var item = $(response).find('item');
$(item).each(function() {
console.log("title" + $(this).find("title").text());
//... 이후 코드는 동일하게 반복
});
console.log(response);
},
error: function(error) {
console.log(error);
}
});
}
</script>
</head>
<body>
<h1>JQuery+Ajax의 조합을 연습하자!</h1>
<hr/>
<div class="question-box">
<h2>3. 랜덤 고양이 사진 API를 이용하기</h2>
<p>예쁜 고양이 사진을 보여주세요</p>
<p>업데이트 버튼을 누를 때마다 지웠다 새로 씌여져야 합니다.</p>
<button onclick="q1()">고양이를 보자</button>
<div>
<img id="img-cat" width="300" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"/>
</div>
</div>
</body>
</html>
댓글 영역