Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
Cant browse through Dictionary in Javascript

I am using Ajax to send data and as a success, it sends some data back.

            $.ajax({
                method: "POST",
                url: "{% url 'upload-prop-images' %}",
                processData: false,
                contentType: false,
                mimeType: "multipart/form-data",
                data: fileData,
                success: function (data) {

                    console.log(data);
                    console.log(data.newCard);
                    console.log(data.newCard.prop_name);

                    }
                }
            })

views.py :

def uploadPropImages(request):

    prop_obj = list(Property.objects.filter(user=request.user).values())
    new_card = {}
    for obj in prop_obj:
        if obj['prop_name'] == prop_name:
            new_card['prop_name'] = obj['prop_name']
            new_card['prop_address'] = obj['prop_address']
            new_card['prop_type'] = obj['prop_type']
            new_card['prop_images'] = '/media/' + obj['prop_images']

    return JsonResponse({'status': 'Done', 'newCard': new_card})

In the first code block where success: function(data) {}, console.log(data) prints the data I am sending, that is {'status': 'Done', 'newCard': new_card}, but when I print, console.log(data.status) or console.log(data.newCard), I get undefined value. I cant understand why it prints undefined because I used AJAX may times earlier and It seem to work. It is how we can browser through the value of a dictionary in JAVASCRIPT, which in PYTHON is print(data['status']). Is the error anything related to the keys defined inside the AJAX function: processData, mimeType, contentType?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you need to call this

$.parseJSON();

Like this

               success: function (response) {
                var data= $.parseJSON(response);
                console.log(data);
                console.log(data.newCard);
                console.log(data.newCard.prop_name);

                }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda