https://developer.mozilla.org/ko/docs/Learn/JavaScript/Objects/JSON
API를 통해서 서버에서 데이터를 JSON의 형태로 받아서 우리가 활용하는 것
클라이언트가 요청할때도 "타입"이라는 것이 존재
-> GET(데이터 조회 요청,read)과
-> POST(데이터 생성, 변경, 삭제)
(이 때는 데이터를 클라이언트에서 제공해주어야 함)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
$.ajax({
type: "GET", // GET 방식으로 요청한다.
url: "http://spartacodingclub.shop/sparta_api/seoulair",
data: {}, // 요청하면서 함께 줄 데이터 (GET 요청시엔 비워두세요)
success: function(response){ // 서버에서 준 결과를 response라는 변수에 담음
console.log(response) // 서버에서 준 결과를 이용해서 나머지 코드를 작성
}
})
function q1() {
//이걸 안하면 업데이트 누를 때마다 계속 이어서 붙여짐
$(`#names-q1`).empty()
$('#img-rtan').attr('src',url)
$('#text-rtan').text(msg)
//위의 둘코드 attr text함수 정의 알아야할듯
ajax03.html 참고
$(document).ready(function () {
listing();
});