I am facing an issue while trying to pass an array in json format using ajax to my django views. Even though I receive a status of 200 indicating that the POST request has been successfully made, when I attempt to display the data passed in another template, I only see 'None' in console. Any help would be greatly appreciated. The objective is to pass a variable to the views which contains an array of json objects, with the intention of creating a new object for the model in my views. Despite multiple attempts, the code below does not seem to work and returns None.
ajax function:
$.ajax({
url: 'http://localhost:8000/order-confirmation',
type: 'POST',
data: {"array":array},
processData: false,
contentType: "application/x-www-form-urlencoded/json",
dataType: "json",
headers: {"X-CSRFToken":'{{ csrf_token }}'},
success: function (result) {
console.log(result.d);
},
error: function (result) {
console.log(result);
}
});
urls:
path("order-confirmation", views.order_confirmation, name="confirmation")
views:
@csrf_exempt
def order_confirmation(request):
array = request.POST.get('array[]')
context = {
"arra...
TEMPLATE:
<div class="container">
<table class="table table-bordered table-dark">
<tbody>
{% for row in seats_range %}
<tr>
...