[Fixed]-Can't get data out of serialized python object in JS/jQuery

1👍

You have a typo:

console.log(data.notifiications[1].fields);

should be:

console.log(data.notifications[1].fields);

0👍

Okay, not sure what was wrong, but this works just fine

$.ajax({
    url: '/notify/',
    type:'GET',
    dataType: 'json',
    success: function (data) {

        alert(data['notifications']);
         var sed = JSON.parse(data['notifications'])
        alert(sed[2].fields.choice_afl);

    }
  });

And in backend,as in EDIT2:

 nots = serializers.serialize('json', Notification.objects.all(), fields=('whom','choice_afl'))
data = {
    'notifications': nots

}
return Response(data)

Leave a comment