본문 바로가기
개발공부 일지/자바스크립트

자바스크립트) 자바스크립트 데이터 전송 및 post 데이터 받기

by Box Cat 2021. 12. 29.
728x90
반응형

https://willbesoon.tistory.com/244

 

function sendPost(url, params) {
    var form = document.createElement('form');
    form.setAttribute('method', 'post'); //POST 메서드 적용
    form.setAttribute('action', url);   // 데이터를 전송할 url
    document.charset = "utf-8";
    for ( var key in params) {  // key, value로 이루어진 객체 params
        var hiddenField = document.createElement('input');
        hiddenField.setAttribute('type', 'hidden'); //값 입력
        hiddenField.setAttribute('name', key);
        hiddenField.setAttribute('value', params[key]);
        form.appendChild(hiddenField);
    }
    document.body.appendChild(form);
    form.submit();  // 전송~
}
728x90
반응형

댓글