i am adding a functionality in which when i click on heart it color should changed to red and added to wihslist

i used ajax for that , my item is being added in wishlist and remved also but color is not being changed . page is refreshing and color is set to default again.

i have passed data and fetching it from database.

   success: function (data) {
                        var heartIcon = $('a[data-data="' + linkData + '"] > i.fa.fa-heart');
                        if (data === '1') {
                            heartIcon.addClass("red-heart");
                        } else {
                            heartIcon.removeClass("red-heart");
                        }
                        console.log(data);