개발/Javascript

[ajax] success 리턴 값에서 함수 실행하기

soohkang 2020. 7. 17. 17:49
728x90
function 함수이름(){
  $.ajax({
  type: "POST",
  url: "phpAjax.php",
  data: data,
  success: function(rtn){
      if(rtn == '00'){
        sucUrl();
      } else {
        alert("다시 시도해주세요.");
      }
    }
  });
}


function sucUrl(){
  var param = "<?=$_POST['param']?>";

  var form = document.createElement("form");
  form.setAttribute("method", "post");
  form.setAttribute("target", name);
  form.setAttribute("action", "https://sururu.tistory.com/");

  var result = document.createElement("input");
  result.setAttribute("type","hidden");
  result.setAttribute("name","param");
  result.setAttribute("value", param);

  form.appendChild(result);

  document.body.appendChild(form);

  form.submit();
}

 

업무에 필요한 내용이라 테스트해봤다.