#Week2 - #7 - Ajax

Arielle·2022년 2월 9일
0

Web Development

목록 보기
7/7

GET

<script>
    $.ajax({
        type: "GET", // GET 방식으로 요청한다.
        url: "http://spartacodingclub.shop/sparta_api/seoulair",
        data: {}, // 요청하면서 함께 줄 데이터 (GET 요청시엔 비워두세요)
        success: function (response) { // 서버에서 준 결과를 response라는 변수에 담음
            console.log(response) // 서버에서 준 결과를 이용해서 나머지 코드를 작성
        }
    })
</script>

<script>
    $.ajax({
        type: "GET", // GET 방식으로 요청한다.
        url: "http://spartacodingclub.shop/sparta_api/seoulair",
        data: {}, // 요청하면서 함께 줄 데이터 (GET 요청시엔 비워두세요)
        success: function (response) { // 서버에서 준 결과를 response라는 변수에 담음
            console.log(response['RealtimeCityAir']['row']) // 서버에서 준 결과를 이용해서 나머지 코드를 작성
        }
    })


    $.ajax({
        type: "GET",
        url: "http://spartacodingclub.shop/sparta_api/seoulair",
        data: {},
        success: function (response) {
            let rows = response['RealtimeCityAir']['row']
            for (let i = 0; i < rows.length; i++) {
                let gu_name = rows[i]['MSRSTE_NM'] //구이름
                let gu_mise = rows[i]['IDEX_MVL'] //미세먼지값
                console.log('구이름: ', gu_name, ',  미세먼지지수: ', gu_mise)
            }

        }
    })
                                       	</script>
profile
Entrepreneur

0개의 댓글