logo

All The Asian Banker Articles By (Matthias Kr%C3%B6ner)

$(document).ready(function () { // Function to update the heart icon color based on like count function updateHeartIconColor(articleId) { var likeCount = parseInt($("#like-count-" + articleId).text(), 10); var heartIcon = $("#heart-icon-" + articleId); if (likeCount === 1) { heartIcon.addClass("heart-red"); } else { heartIcon.removeClass("heart-red"); } } // Update the heart icon color on page load $(".like_article").each(function () { var articleId = $(this).data("id"); updateHeartIconColor(articleId); }); // Event listener for the like button click $(".like_article").on("click", function () { var articleId = $(this).data("id"); console.log("Article ID:", articleId); // Debugging line if (!articleId) { alert("Article ID is missing!"); return; } $.ajax({ url: "https://live.theasianbanker.com/articlesfront/like_article", type: "POST", data: { article_id: articleId }, dataType: "json", success: function (response) { console.log(response); // Debugging line // Update the like count and heart icon color $("#like-count-" + articleId).text(response.new_like_count); updateHeartIconColor(articleId); location.reload(); } }); }); });