spring html에서 script로 get post처리하기

이태규·2022년 4월 7일
0

spring

목록 보기
47/64
<button th:onclick="|javascript:handleDelete('${tmp.icode}')|">삭제</button>

<script>
		function handleDelete(no){
            if(confirm('삭제할까?')){
                console.log(no);
                // GET으로 삭제처리 주소창을 바꿈
                // location.href="/ROOT/seller/deleteitem?code="+no

                // post로 처리
                // <form th:action="@{/seller/deleteitem}" method= "post"></form>을 만듦
                const form = document.createElement("form");
                form.method= "post";
                form.action = "/ROOT/seller/deleteitem";

                // <input type="text" name="code" value="전달되는 번호" />
                const input = document.createElement("input");
                input.name="code";
                input.value = no;

                // form document에 추가
                form.appendChild(input);

                // form document에 추가
                document.body.appendChild(form);

                // <input type="submit">를 누름
                form.submit();
            }
		}
</script>
profile
한 걸음씩 나아가자

0개의 댓글