Is there a way to implement a like button in Django using ajax without the need for a page reload? I've tried setting up my HTML and Ajax function, but it's not working properly.
<form method="POST" action="{% url 'video:like' video.pk %}">
{% csrf_token %}
<input type="hidden" class="likin" name="next" value="{{ request.path }}">
<button class="remove-default-btn" type="submit">
<i class="fa fa-thumbs-up" aria-hidden="true"><span>{{ video.likes.all.count }}</span></i>
</button>
JavaScript
$('.likin').click(function(){
$.ajax({
type: "POST",
url: "{% url 'video:like' video.pk %}",
data: {'content_id': $(this).attr('name'),'operation':'like_submit','csrfmiddlewaretoken': '{{ csrf_token }}'},
dataType: "json",
success: function(response) {
selector = document.getElementsByName(response.next);
if(response.liked==true){
$(selector).css("color","blue");
}
else if(response.liked==false){
$(selector).css("color","black");
}
}
});
})