I have this script:
<script type="text/javascript">
        function requestimg(username){
                $.ajax({
                    url: '{% url "image" %}',
                    data: {
                      'username': username
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            //Printing the whole data
                            console.log(data);
                            //Printing to see where I am
                            console.log("Name: ");
                            //Trying to rint the name
                            console.log(data[0].nombre);
                        }else {
                             alert("May Day");
                        }
                    }
                });
        }
I have a problem reading the properties in the json object When i print the data I get this:
{
    json: "[
        {
            "model": "polls.imagen",
            "pk": 17,
            "fields": {
                "n…"36",
                "imagen": "polls/static/pictures/dr.jpg"
            }
        }
    ]"
}
And when i print the data as I have it on the code i get:
Uncaught TypeError: Cannot read property 'nombre' of undefined
I have tryied writing it like data.nombre but i just get undefined
I have also tried this console.log(data[0].fields); , data[0].model, data.model
IMPORTANT I want to clarify that i wont know why there are 2 json objects im supposed to get just one and even if i try to put a [1] instead of the [0] i get the same mistakes.
I've tried answers from some previous similar questions and they didn't help.
 
     
     
    