function clickLikeBtn(event, obj) { event.preventDefault(); event.stopPropagation(); const no = $(obj).data("no"); const element = $(obj); if (element.hasClass("active")) { // like -> dislike $.post("ajax/likeAjax.jsp", { post_no: no, state: "like", async: false }, function(response) { const result = JSON.parse(response); if (result['result']) { element.removeClass("active"); $.ajax({ url: "ajax/likeCount.jsp", method: 'POST', data: { no: no, tablename: "postLikes" }, dataType: "json", success: function(json) { console.log(json) if (json['success']) { $("#like_number_" + no).text(json['count']); } else { $("#like_number_" + no).text(json['count']); } }, error: function() { alert("오류가 발생했습니다."); } }); } else { alert("오류가 발생했습니다.") } }) .fail(function(error){ alert("오류가 발생했습니다."); }) } else { // dislike -> like $.post("ajax/likeAjax.jsp", { post_no: no, state: "dislike", async: false }, function(response) { const result = JSON.parse(response); if (result['result']) { element.addClass("active"); $.ajax({ url: "ajax/likeCount.jsp", method: 'POST', data: { no: no, tablename: "postLikes" }, dataType: "json", success: function(json) { console.log(json) if (json['success']) { $("#like_number_" + no).text(json['count']); } else { $("#like_number_" + no).text(json['count']); } }, error: function() { alert("오류가 발생했습니다."); } }); } else { alert("오류가 발생했습니다.") } }) .fail(function(error) { alert("오류가 발생했습니다."); }) } }