220414 - Ajax(따릉이)

김정현·2022년 4월 14일
0
  • 따릉이 수
.ddalung{
    color: red;
}
</style>

<script>
function q1() {
     $('#names-q1').empty()
     $.ajax({
type: "GET",
url: "http://spartacodingclub.shop/sparta_api/seoulbike",
data: {},
success: function(response){
    let rows = response['getStationList']['row']
    for (let i = 0; i < rows.length; i++) {
        let name = rows[i]['stationName']
        let rack = rows[i]['rackTotCnt']
        let park = rows[i]['parkingBikeTotCnt']

        let temp_html=``

        if (park<5){
             temp_html= `<tr class="ddalung">
                            <td>${name}</td>
                            <td>${rack}</td>
                            <td>${park}</td>
                            </tr>`
        }else{
             temp_html= `<tr>
                            <td>${name}</td>
                            <td>${rack}</td>
                            <td>${park}</td>
                            </tr>`
        }





        $('#names-q1').append(temp_html)
     }
}
})

}
  • let rows = response['getStationList']['row']를 입력할때 (['getStationList']['row'])소괄호를 입력하여 실행되지 않았다.
  • let park = rows[i]['parkingBikeTotCnt']를 입력할때 ['"parkingBikeTotCnt'] 큰 따옴표가 같이 복사되었는데 확인하지 못했다. 괄호, 철자, 따옴표 신경쓰자
  • temp_html 순서가 헷갈림 복습 필요
  • 전체적으로 실수하지 않게 주의

0개의 댓글