Ajax 코드 바닐라&제이쿼리

Jaden·2023년 6월 12일
0

바닐라

function action1() {
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'update_forex_first.php', true);
  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4 && xhr.status === 200) {
      // 요청이 성공적으로 완료되었을 때 실행할 코드 작성
      // ...
    }
  };
  xhr.send();
}

function action2() {
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'update_forex.php', true);
  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4 && xhr.status === 200) {
      // 요청이 성공적으로 완료되었을 때 실행할 코드 작성
      // ...
    }
  };
  xhr.send();
}

AJAX

function action1() {
  $.ajax({
    url: 'update_forex_first.php',
    type: 'POST',
    success: function(response) {
      // 요청이 성공적으로 완료되었을 때 실행할 코드 작성
      // ...
    },
    error: function(xhr, status, error) {
      // 요청이 실패했을 때 실행할 코드 작성
      // ...
    }
  });
}

function action2() {
  $.ajax({
    url: 'update_forex.php',
    type: 'POST',
    success: function(response) {
      // 요청이 성공적으로 완료되었을 때 실행할 코드 작성
      // ...
    },
    error: function(xhr, status, error) {
      // 요청이 실패했을 때 실행할 코드 작성
      // ...
    }
  });
}

AJAX-코드추가

function update_forex_action1() {
      var form = document.fx_insert;
      var data = new FormData(form);
     
      $.ajax({
        url: 'update_forex_first.php',
        type: 'POST',
        data: data,
        processData: false,
        contentType: false,
        success: function(response) {
          alert(response);
        },
        error: function(xhr, status, error) {
          alert("요청실패");
        }
      });
    }
    
    function update_forex_action2() {
      var form = document.fx_insert;
      var data = new FormData(form);
      $.ajax({
        url: 'update_forex.php',
        type: 'POST',
        data: data,
        processData: false,
        contentType: false,
        success: function(response) {
          alert(response);
        },
        error: function(xhr, status, error) {
          alert("요청실패");
        }
      });
    }
profile
Quadrilingual Programmer

0개의 댓글