08-02-2023, 04:52 PM
data: {"csrfmiddlewaretoken" : "{{csrf_token}}"}
You see "403 (FORBIDDEN)", because you don`t send "csrfmiddlewaretoken" parameter.
In template each form has this: {% csrf_token %}.
You should add "csrfmiddlewaretoken" to your ajax data dictionary. My example is sending "product_code" and "csrfmiddlewaretoken" to app "basket" view "remove":
$(function(){
$('.card-body').on('click',function(){
$.ajax({
type: "post",
url: "{% url 'basket:remove'%}",
data: {"product_code": "07316", "csrfmiddlewaretoken" : "{{csrf_token}}" }
});
})
});
You see "403 (FORBIDDEN)", because you don`t send "csrfmiddlewaretoken" parameter.
In template each form has this: {% csrf_token %}.
You should add "csrfmiddlewaretoken" to your ajax data dictionary. My example is sending "product_code" and "csrfmiddlewaretoken" to app "basket" view "remove":
$(function(){
$('.card-body').on('click',function(){
$.ajax({
type: "post",
url: "{% url 'basket:remove'%}",
data: {"product_code": "07316", "csrfmiddlewaretoken" : "{{csrf_token}}" }
});
})
});