카테고리 없음

내배캠 4일차

하늘유니콘 2023. 3. 19. 02:36
 
if (idx == gbook_idx) {
 
let gbook_password = gbook.pw
 
if (pwd == gbook_password) {
 
update_book(idx)
 
} else {
 
alert('비밀번호를 확인해주세요')

문제점 비밀번호를 수정창을 띄워서 실행하는게 문제점

 
// 수정 창 띄우기
 
function update_book(idx) {
 
 
 
let idx_selected = idx
 
let id = 'updatepg/' + idx
 
 
 
let formData = new FormData();
 
 
 
formData.append("idx_", idx_selected);
 
fetch('/update', { method: "POST", body: formData })
 
.then((res) => res.json())
 
.then((data) => {
 
 
 
window.open(id,"update","width = 500, height = 500, top = 100, left = 200, location = no")
 
 
 
})
 
}

 

 

 
// 수정하기
 
function save_updated_comment() {
 
let updated_nickname = $('#updated_nickname').val() //문자열
 
let updated_comment = $('#updated_comment').val()
 
let element = document.getElementById('id_idx')
 
let idxx = element.innerText
 
let name_element = document.getElementById('myname')
 
let my_name = name_element.innerText
 
 
 
let formData = new FormData();
 
formData.append("idxx_give", idxx);
 
formData.append("up_nickname_give", updated_nickname);
 
formData.append("up_comment_give", updated_comment);
 
// 유효성 검사
 
if (updated_nickname.trim() == '') {
 
alert('닉네임을 입력해주세요.')
 
} else if (updated_comment.trim() == '') {
 
alert('내용을 입력해주세요.')
 
} else {
 
fetch('/saveupdate', { method: "PUT", body: formData, })
 
.then((res) => res.json())
 
.then((data) => {
 
alert(data["msg"]);
 
opener.opener.location.reload();
 
window.close()
 
});
 
}
 
}

해결책 featch로 수정한 값을 저장하고 해다url을 확인하고 if문을 쓰는걸로 팀장님이

해결하셨다.