これはcallback地獄と呼ばれています.

13548 ワード

<script th:inline="javascript">
    $("#reply").on('click', function () {
        var inqIdx = [[${inquiry.inq_idx}]];

        $.ajax({
            url: "/bbs/inquiry/detail/reply/duplicated?inqIdx=" + inqIdx,
            type: 'GET',
            success: function (result) {
                if (result.rtnCode === '0001') {
                    if (confirm("수정하시겠습니까?")) {
                        $.ajax({
                            url: "/bbs/inquiry/detail/reply/update",
                            type: 'POST',
                            data: {
                                "inqIdx": inqIdx,
                                "content": $("#content").val()
                            },
                            success: function (result) {
                                alert('성공');
                                document.getElementById('content').removeAttribute('disabled');
                                document.getElementById('reply').removeAttribute('disabled');
                                location.reload();
                            },
                            error: function (result) {
                                console.log('실패');
                            }
                        });
                    }
                } else {
                    if (confirm("답변을 등록하시겠습니까?")) {
                        $.ajax({
                            url: "/bbs/inquiry/detail/reply",
                            type: 'POST',
                            data: {
                                "inqIdx": inqIdx,
                                "content": $("#content").val()
                            },
                            success: function (result) {
                                alert('성공');
                                location.reload();
                            },
                            error: function (result) {
                                console.log('실패');
                            }
                        });
                    }
                }
            },
            error: function (result) {
                console.log('실패');
            }
        });
    })

    $(".modify_btn").on('click', function () {
        document.getElementById('content').removeAttribute('disabled');
        document.getElementById('reply').removeAttribute('disabled');
    })
</script>
JavaScriptを学びたいです.1日20分の投資