I need to pass a Json Object value after making an API call to my views.py in order to render in django template. After making an ajax call I'm not able to get the value in django`
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)
}
})`
in my 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')
the print method in def kycsubmit(request): it will only print to the terminal. Use context variable here
def kycsubmit(request): """ A view to return the index page""" if is_ajax(request=request): if request.method == 'GET': data = request.GET.get('senddata') return render(request, 'kycsubmit/onboard.html',{'data':data})