-
자바스크립트로 post 전송javascript 2016. 6. 28. 14:16function 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>댓글