호아's Diary

1. ajax 

function q1() {
$('#names-q1').empty()     <-  q1 함수 시작 시 names-q1의 값을 모두 지운다.  
   $.ajax({
     type: "GET",
     url: " ",  <- url를 통해서 정보를 받아온다
     data: {},
     success: function (response) {
console.log(response)     <-  첫 번째 확인  주소 값만 넣은 후 콘솔 창에 데이터 확인하기(정삭 동작시 삭제 후 다음 단계 넘어가기)

     let rows = response['getStationList']['row']      
             
     console.log(rows) <- 두 번째 확인 리스트 안에 row 영역만 출력되는지 콘솔 창에 데이터 확인하기(정삭 동작시 삭제 후 다음 단계 넘어가기) 

     for (let i = 0; i < rows.length; i++) {

console.log(rows[i]) <- 세 번째 확인 row영역이 돌면서 하나씩 출력되는지 콘솔 창에 데이터 확인하기(정삭 동작시 삭제 후 다음 단계 넘어가기) 

     let name = rows[i]['stationName']
     let parking = rows[i]['parkingBikeTotCnt']
     let rack = rows[i]['rackTotCnt']

console.log(name, parking, rack) <- 네 번째 확인 원하는 정보만 출력되는지 콘솔 창에 데이터 확인하기(정삭 동작시 삭제 후 다음 단계 넘어가기)
그리고 hemp_html 을 통해서 내용 붙이기  
 

      let temp_html = ``
                         if(parking > 10){
                                   temp_html = `<tr class='red'>
                                        <td>${name}</td>
                                        <td>${rack}</td>
                                        <td>${parking}</td>
                                                 </tr>`
                            }
                            else{  temp_html = `<tr>
                                        <td>${name}</td>
                                        <td>${rack}</td>
                                        <td>${parking}</td>
                                                 </tr>`
                            }

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

 

2. requests

r = requests.get('')
rjson = r.json()

print(rjson)
이렇게 하면 ajax에서 썼을 때 보였던 형태를 볼 수 있다.

print(rjson)['RealtimeCityAir']['row']

이렇게 하면 ajax에서 보았던 row 값만 나온다.


a = rjson['RealtimeCityAir']['row']

for b in a:
print(b)

그리고 이렇게 하면 하나씩 돌면서 row의 값이 나온다.

a = rjson['RealtimeCityAir']['row']

for b in a:
c = b['MSRSTE_NM']
d = b['IDEX_MVL']
print(c,d)

이렇게 하면 지역과 먼지 값만 쭈욱 출력이 되는 걸 볼 수 있다.

오늘 느낀 점

  • 콘솔 창을 활용하자
  • 문제점을 파악하고 구글링 능력을 높이자

내일 할 일

  • 웹 프로그래밍 A-Z 기초 복습
  • TIL (Today I learned) 작성하기
  • 체크인, 체크아웃 하기

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading