When I attempt to pass a Json Object value from making an API call to my views.py in Django template, I encounter difficulty retrieving the value after an ajax call.
let application = JSON.parse(sessionStorage.getItem("appId"));
let kycStatus = application.applicationId
$.ajax({
type: "GET",
dataType: "json",
url: `${url}/${kycStatus}`,
headers: {
'Content-Type': 'application/json',
'X-API-Key': '',
},
data: {
senddata: JSON.stringify(),
},
success: function(data) {
document.getElementById("kyc-status").innerHTML = data.overallResult.status
console.log(data.overallResult.status)
}
})`
I face challenges getting the value in django's views.py.
def is_ajax(request):
return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
def kycsubmit(request):
""" A view to return the index page"""
if is_ajax(request=request):
if request.method == 'GET':
data = request.GET.get('senddata')
print(data)
return render(request, 'kycsubmit/onboard.html')