javascript/Ajax

javascript Ajax Code

WS.GI 2023. 7. 22. 03:14
여러분의 후원은 큰 힘이 됩니다. 기업은행 35611080101018
반응형
function sample(){
  let url = "/url";
  let xhr ='';
  let jsonData = '';

  if (window.XMLHttpRequest) { // 모질라, 사파리, IE7+ ...
      xhr = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // IE 6 이하
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
  }
  // XMLHttpRequest 객체 생성 및 요청 수행
      xhr.open("POST", url, true);
      xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      xhr.send(jsonData);

      xhr.onreadystatechange = function() {
        if ( xhr.readyState == 4 ) {
          if ( xhr.status == 200 || xhr.status == 201 ){
            xhr.responseJSON = JSON.parse(xhr.response);
          }
        } else if ( xhr.readyState == 3 ) {

        } else if ( xhr.readyState == 2 ) {

        } else if ( xhr.readyState == 1 ) {

        } else if ( xhr.readyState == 0 ) {

        }
      }
}
반응형

'javascript > Ajax' 카테고리의 다른 글

jquery Ajax Code  (0) 2023.07.22
Ajax  (0) 2023.07.21