如何将字典a
添加到response
,如何在two objects
获得ajax
?
视图
def abc(request):
cp = Cp.objects.get(id=1)
cp = serializers.serialize('json', [cp,])
cp = json.loads(cp)
a = {'a': 'a', 'b': 'b'}
return HttpResponse(data)
js
$.ajax({
//
success: function(data){
}
})
答案 0 :(得分:2)
Thnx @WillemVanOnsem寻求帮助
观看次数
def abc(request):
cp = serializers.serialize('json', [cp,])
cp = json.loads(cp)
cp = json.dumps(cp)
other = {'rate': float(rate), 'eair': float(eair), 'overpayment': overpayment, 'total_payment': round(total_payment), 'monthly_payment':round(monthly_payment)}
return JsonResponse({'cp': cp, 'other': other})
js
$.ajax({
//
success: function(data) {
var cp_json = JSON.parse(data.cp);
var other = data.other;
var credit_payment = cp_json[0].fields;
$('.rate').html(credit_payment.rate + '%')
}
})