Ajax

송민지·2022년 2월 21일
0

웹개발 종합반

목록 보기
13/27

Ajax는 jQuery를 임포트한 페이지에서만 동작 가능하다.

Uncaught TypeError: $.ajax is not a function
→ ajax라는 게 없다는 뜻

Ajax 기본 골격

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

$ajax 코드 설명

  • type: "GET" → GET 방식으로 요청한다.
  • url: 요청할 url 👉 리마인드 GET 요청은, url뒤에 아래와 같이 붙여서 데이터를 가져간다. http://naver.com?param=value¶m2=value2

POST 요청은, data : {} 에 넣어서 데이터를 가져간다.
data: { param: 'value', param2: 'value2' },

success: 성공하면, response 값에 서버의 결과 값을 담아서 함수를 실행한다.

success: function(response){ // 서버에서 준 결과를 response라는 변수에 담음
  console.log(response) 
}
profile
기록하는 일상

0개의 댓글