Кнопка добавления в корзину не реагирует

Я внедрял новые функции на сайт электронной коммерции и внезапно кнопка "Добавить в корзину" перестала работать. Когда пользователь нажимает кнопку "Добавить в корзину", сайт отправляет запрос "add" в файл views.py, и вся логика происходит здесь:

views.py

def updateItem(request):
data = json.loads(request.body)
productId = data['productId']
action = data['action']
print('Action:', action)
print('Product:', productId)

customer = request.user.customer
product = Product.objects.get(id=productId)
order, created = Order.objects.get_or_create(customer=customer, complete=False)

orderItem, created = OrderItem.objects.get_or_create(order=order, product=product)

if action == 'add':
    orderItem.quantity = (orderItem.quantity + 1)
elif action == 'remove':
    orderItem.quantity = (orderItem.quantity - 1)

orderItem.save()

if orderItem.quantity <= 0:
    orderItem.delete()

return JsonResponse('Item was added', safe=False)

store.html

{% block content %} 
................................
    <div class="row">

    {% for product in products %}
    <div class="col-lg-3">
        <hr style="width:0">
        <img class="thumbnail" src="{{ product.imageURL }}" style="border-radius: 15px;" alt="">

        <div class="box-element product" id="box_product_element">
            <h6><strong>{{product.name}}</strong></h6>
            <hr>

            <button data-action="add" class="btn btn-outline-success add-btn update-cart" style="border-radius: 10px;">Add</button>

            <a class="btn btn-outline-secondary" href="{% url 'product-detail' product.category.slug product.slug%}" style="border-radius: 10px;">View</a>              <h4 style="display: inline-block; float: right"><strong>${{product.price|floatformat:2}}</strong></h4>

        </div>
    </div>

    {% endfor %}


</div>
...............................
    {% endblock content %}

Когда пользователь нажимает на кнопку, сайт не обновляется, следовательно должна быть проблема с отправкой запроса из HTML? Пожалуйста, помогите мне исправить это.

Вернуться на верх