Ajax

jerome·2020년 8월 27일
0
  • Ajax(Asynchronous JavaScript and XML)요청에 대해서 자세히 알아본다
  • 자바스크립트를 이용해서 비동기식으로 서버와 통신
  • 최근에는 JSON을 많이 사용
    $.ajax({
        url: url,
        // HTTP 요청 방식(기본값은 'GET')
        type: type,
        dataType: dataType,
        // true(비동기, 기본값), false(동기)
        async: true,
        // GET방식일때 유효
        cache: false,
        // ajax요청을 보내기 직전에 실행하는 콜백함수(jqXHR객체를 수정할 수 있다)
        beforeSend: function(xhr, opts) {
          // xhr.abort() ajax 전송 막기
          // xhr.setRequestHeader
        },
        // ajax요청이 성공했을 경우
        success: function() {},
        // ajax요청이 실패했을 경우
        error: function(request, status, error) {},
        // error나 success Callback 함수가 수행된 후에 실행되는 함수
        // try ~ catch ~ finally에서 finally와 같다
        complete: function(xhr, status) {}
    });

참고
https://developer.mozilla.org/ko/docs/Web/API/XMLHttpRequest
https://api.jquery.com/jquery.ajax/
https://devyj.tistory.com/1
https://opentutorials.org/course/1375/6851
https://visualize.tistory.com/402
https://m3rri-developer.tistory.com/11

profile
프론트엔드 개발 🌱

0개의 댓글