I try to submit data on change and change the response from the view based on the data from the POST request.
$.ajax({
url: $basicAnalysisChart.data("url"),
type: "POST",
headers:{
"X-CSRFToken": csrftoken
},
dataType: "json",
contentType: 'application/json; charset=utf-8',
data:{
selector1:$("#Select1").val(),
selector2:$("#Select2").val()
},
i tried getting to that data in my view with request.POST.get("Select1", "")
and request.POST.get("selector1", "")
but cant get it working.
2
Answers
i didnt format the json object right, so it couldnt work. Porblem solved
As your data type is JSON, in django you should say
instead of:
From the documentation: "If you need to access raw or non-form data posted in the request, access this through the HttpRequest.body attribute instead."
here is the link to documentation: https://docs.djangoproject.com/en/3.2/ref/request-response/#django.http.HttpRequest.POST