Ajax - 웹개발 종합반 기초 1,2,3 주차

HTML,CSS,JS

목록 보기
3/16

ajax는 jquery를 임포트한 페이지에서만 동작 가능!

# Ajax 기본 골격
$.ajax({
  type: "GET",
  url: "여기에URL을입력",
  data: {},
  success: function(response){
    console.log(response)
  }
})

# 코드 해설
$.ajax({
  type: "GET", // GET 방식으로 요청한다.
  url: "http://openapi.seoul.go.kr:8088/.../json/RealtimeCityAir/1/99",
  data: {}, // 요청하면서 함께 줄 데이터 (GET 요청시엔 비워두기)
  success: function(response){ # 서버에서 준 결과를 response라는 변수에 담음
    console.log(response) # 서버에서 준 결과를 이용해서 나머지 코드를 작성
  }
}) # success: 성공하면, response 값에 서버의 결과 값을 담아서 함수를 실행한다.


profile
백엔드를 공부하고 있습니다.

0개의 댓글