🎶 코드 수정 전
function updatePost(){
let id=document.getElementById('postId').value;
let isUpdate=confirm("정말 수정하시겠습니까?");
if(isUpdate){
window.location.href="/post/detail/"+id;
}
}
window.location.href는 GET방식으로 요청을 보낸다.
하지만, 내가 작성한 코드는 PUT방식으로 요청을 받아야했다.
🎶 코드 수정 후
function updatePost(){
let id=document.getElementById('postId').value;
let isUpdate=confirm("정말 수정하시겠습니까?");
if(isUpdate){
return true;
}else {
return false;
}
}
<button type="submit" class="btn btn-primary" th:if="${#strings.equals(post.author, username)}" onclick="return updatePost();">수정</button>
updatePost 함수를 실행하고 true를 리턴받았을 때 form을 submit하는 버튼이다.
참고 👇
https://stackoverflow.com/questions/2367979/pass-post-data-with-window-location-href
pass post data with window.location.href
When using window.location.href, I'd like to pass POST data to the new page I'm opening. is this possible using JavaScript and jQuery?
stackoverflow.com
반응형
'FE > html' 카테고리의 다른 글
[Thymeleaf] 게시글 상세보기에서 댓글 개수 출력 (0) | 2022.07.07 |
---|---|
[JS] 댓글 작성/수정/삭제 후 비동기 방식으로 출력 (0) | 2022.07.06 |
[Bootstrap] class="invalid-feedback"이 작동하지 않을 때 (0) | 2022.06.06 |
[Thymeleaf] th:attr로 속성에 값 할당하기 (0) | 2022.06.03 |
[Bootstrap] 부트스트랩의 아이콘 사용하기 (0) | 2022.06.02 |