Jquery Ajax를 사용할려면 어느 시점에 이벤트가 발생하는지 알아볼 필요가 있습니다. 그건 보통 "라이프사이클"이라고도 부릅니다. ReactJS, VueJS...등등 과 같은 라이브러리도 이런 라이프사이클들이 존재 합니다.
jQuery 최신버전에서 사용가능한 메서드들
메서드
설명
ajaxStart
첫 번째 Ajax 요청이 시작될 시점에 호출 할 핸들러를 등록한다. (ex 로딩 이미지 보여주기 처리)
ajaxStop
모든 Ajax 요청이 완료되는 시점에 호출 할 핸들러를 등록한다. (ex 로딩 이미지 감추기 처리)
done
요청 성공시 호출
fail
요청 실패시 호출
always
성공 실패 상관없이 호출
jQuery 구버전에서 사용가능한 메서드들
메서드
설명
timeout
응답제한시간 ms
success
요청 성공시 호출
beforeSend
ajax 요청하기전에 실행되는 함수 (ex 로딩 이미지 보여주기 처리)
complete
정상이든 비정상인든 실행이 완료될 경우 실행될 함수 (ex 로딩 이미지 감추기 처리)
error
요청 실패시 호출
//main.json
[
{
"id": 1,
"name": "Mocade",
"price": 350,
"img": "img/pic4.jpg",
"title": "Black Mocade",
"text": "Hey look up! It's a plane! No, It's a bird! No, it's the assassin performing leap of faith."
},
{
"id": 2,
"name": "zipper",
"price": 59,
"img": "img/pic5.jpg",
"title": "No zipper dress",
"text": "The price of this dress has been cut off since we lost the zipper on the back."
},
{
"id": 3,
"name": "ernest",
"price": 299,
"img": "img/pic6.jpg",
"title": "Dear Ernest",
"text": "We'll bring readers to the edge of ther seats and keep them there until we sell this dress."
}
]