31
2017-Jul
[javascript] POST 전송하기
작성자: Blonix
IP ADRESS: *.64.228.3 조회 수: 1605
출처: http://kanitz.tistory.com/121
function post_to_url(path, params, method) {
method = method || "post"; // 전송 방식 기본값을 POST로
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
//히든으로 값을 주입시킨다.
for(var key in 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();
}
사용할때는
<a href="javascript:post_to_url('www.XXXX.com/XXXXhtml',{'type1':'aaa','type2':'bbb'})">POST보내기</a>