Add Answer Delete button and script

This commit is contained in:
MangKyu
2022-01-07 01:04:37 +09:00
parent 690c7b930b
commit e61bac641f
2 changed files with 29 additions and 1 deletions

View File

@@ -13,6 +13,10 @@ $(document).ready(function () {
$("#btn-edit-answer").click(function () { $("#btn-edit-answer").click(function () {
editAnswer(editor); editAnswer(editor);
}); });
$("#btn-delete-answer").click(function () {
deleteAnswer();
});
}); });
function editAnswer(editor) { function editAnswer(editor) {
@@ -23,6 +27,7 @@ function editAnswer(editor) {
alert("Input description"); alert("Input description");
return false; return false;
} }
$.ajax({ $.ajax({
url: '/answer', url: '/answer',
type: 'PUT', type: 'PUT',
@@ -32,11 +37,33 @@ function editAnswer(editor) {
'description': description 'description': description
}), }),
success: function () { success: function () {
$("#answerResourceId").val('a');
alert("설명 추가 성공") alert("설명 추가 성공")
window.location = window.location
}, },
error: function (e) { error: function (e) {
alert("설명 추가 실패"); alert("설명 추가 실패");
} }
}); });
}
function deleteAnswer() {
const answerResourceId = $("#answerResourceId").val();
if (!answerResourceId) {
alert("Answer Not Exists");
return false;
}
$.ajax({
url: '/answer/' + answerResourceId,
type: 'DELETE',
contentType: 'application/json',
success: function () {
alert("설명 삭제 성공");
window.location = window.location
},
error: function () {
alert("설명 삭제 실패");
}
});
} }

View File

@@ -42,6 +42,7 @@
</div> </div>
<div class="form-group mt-3"> <div class="form-group mt-3">
<button type="submit" class="button boxed-btn" id="btn-edit-answer">Edit</button> <button type="submit" class="button boxed-btn" id="btn-edit-answer">Edit</button>
<button type="submit" class="button boxed-btn" id="btn-delete-answer">Delete</button>
</div> </div>
</div> </div>
</div> </div>