кнопка лайка на сайте django с помощью ajax

Написал систему лайков для своего сайта. столкнулся с проблемой что после нажатия на кнопку лайка страница обновляется и нужно заного скролить страницу до момента где была нажата кнопка лайка. я как понял что решается это все через отправку ajax запросов но так и не дошло что я с этими запросами делаю не так

views.py

def like(request, post_id):
    post = get_object_or_404(UserPost, pk=post_id)
    if request.user in post.likes.all():
        post.likes.remove(request.user)
        liked = False
    else:
        post.likes.add(request.user)
        liked = True
    post.save()
    data = {'likes_count': post.likes.count()}
    return JsonResponse(data)

html

    {% for post in posts %}
        <h1><a href="{% url 'post_detail' post.id %}">{{ post.title }}</a></h1>
        <h2>{{ post.body }}</h2>
        <div>
            <form action="{% url 'likes' post.id %}" method="post">
                {% csrf_token %}
                <p>Likes: <span id="like-count-{{ post.id }}">{{ post.likes.count }}</span></p>
                <button id="like" type="submit" name="post_id" data-post-id="{{ post.id }}">Нравится</button>
            </form>
        </div>
        <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
        <script>
            $(document).ready(function () {
                $('#like').click(function () {
                    var postId = $(this).data('post-id');
                    $.ajax({
                        url: '{% url "likes" post.id %}',
                        type: 'POST',
                        data: { 'post_id': postId },
                        dataType: 'json',
                        success: function(response) {
                            $('#like-count-' + postId).text(response.likes);
                        },
                        error: function(xhr, status, error) {
                            console.log(error);
                        }
                    });
                });
            });
        </script>
    {% endfor %}
{% endblock %}

Ответы (0 шт):