개발나들이/front
ajaxstart() 와 ajaxstop() 사용방법
Ililing
2019. 7. 23. 16:39
웹사이트를 구축할 때 ajax 요청이 이루어지는 시간 동안 특정 메세지나 문구, 로딩 이미지를 사용자에게 알려줄 경우가 생긴다.
이 때 이를 쉽게 처리할 수 있는 방식으로 ajaxStart() 와 ajaxStop() 를 적어보고자 한다.
ajaxStart() 메소드 - AJAX 요청이 시작되는 시점에 해당 함수를 실행
ajaxStop() 메소드 - 실행중인 모든 AJAX 요청이 멈추게되면 해당 함수를 실행
[사용방법]
ajaxStart()
<div><img id="loading" src="loading.gif"></div>
<script>
$(document).ajaxStart(function () {
$("#loading").show();
});
</script>
ajaxStop()
<div><img id="loading" src="loading.gif"></div>
<script>
$(document).ajaxStop(function () {
$("#loading").hide();
});
</script>