Answer the question
In order to leave comments, you need to log in
Why doesn't Ajax work in Django?
Trying to add to cart via ajax, getting 403 Forbidden error
<script>
$( ".add_to_cart" ).submit(function(addr) {
$.ajax({
type: "POST",
url: String($('.add_to_cart').data("action")),
success: function() {
$('.main-offer_list').html(`{% for item in cart %}
{% with product=item.product %}
<div class="main-offer_list-item">
<div class="main-offer_list-info">
<div class="main-offer_list-title">
{{ product.name }}
</div>
<!-- <div class="main-offer_list-calc">
1
</div> -->
</div>
<img src="{{ product.image.url }}" alt="">
<div class="main-offer_list-close">
<a href="{% url 'cart:cart_remove' product.id %}"><img class="img-svg" src="{% static 'img/close.svg' %}" alt=""></a>
</div>
</div>
{% endwith %}
{% endfor %}`);
}
});
});
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question