Such related question I have seen so many but none solved my problem. There is other reason why this is not working but I am feeling difficult to figure out the issue. Here is the code
base.html
{% block pagecontent %}
{% endblock pagecontent %}
{% block js %}
{% include 'includes/js.html' %}
$(document).ready(function(){
function updateText(btn, newCount, verb){
btn.text(newCount + " " + verb)
}
$(".like-company").click(function(e){
e.preventDefault()
var this_ = $(this)
var likeUrl = this_.attr("data-href")
var likeCount = parseInt(this_.attr("data-likes")) | 0
var addLike = likeCount + 1
var removeLike = likeCount - 1
if (likeUrl){
$.ajax({
url: likeUrl,
method: "GET",
data: {},
success: function(data){
console.log(data)
var newLikes;
if (data.liked){
updateText(this_, addLike, "Unlike")
} else {
updateText(this_, removeLike, "Like")
}
}, error: function(error){
console.log(error)
console.log("error")
}
})
}
})
})
{% endblock js %}
includes/js.html
{% load static %}
home.html
{% extends 'base.html' %}
{% block pagecontent %}
{% if companies %}
COMPANIES
{% for company in companies %}
{% if forloop.first %}
{% endfor %}
{% endif %}
{% endblock pagecontent %}
I have checked that the jquery is loaded and also the code is working up to if (likeUrl)