In the django function, I send data to JS via JSON
startdate = datetime.strptime(request.POST['startdate'], '%d.%m.%Y') enddate = datetime.strptime(request.POST['enddate'], '%d.%m.%Y') paymentparking = paidparking.objects.filter(expirationdate__range = (startdate, enddate)).values('expirationdate', 'price') return JsonResponse(dict(paymentparking))
How do I get price and expirationdate separately in JS?
$.ajax({ type: "POST", url: "statistics", data: { 'startdate': finalDateStrStart,'enddate': finalDateStrEnd, }, dataType: "json", cache: false, success:function (data) { } });
This is what I get in the django function before sending the JSON:
<QuerySet [{'expirationdate': datetime.date(2021, 4, 30), 'price': 300.0}, {'expirationdate': datetime.date(2021, 5, 5), 'price': 750.0}]>
If success:
function (data) { console.log(data) }
As a result, I get:
I need to get the price and expirationdate separately. How can this be done?
https://stackoverflow.com/questions/67426189/getting-data-from-json-to-js May 07, 2021 at 05:29AM
没有评论:
发表评论