bucle de los pares clave/valor

I'm trying to loop the key/value pairs I receive below in my query and console out the email address. What I'm I doing wrong?

JSON I receive...


Current Script

        var digits = /^\d{11}$/;
        $("#mobile").on("keyup keypress", function(){

            if (digits.test(this.value)) {
                    url: "http://api.domain.com/recipients/lookup",
                    data: {
                        mobile: this.value,
                        incentiveID:  $("#incentiveID").val()
                    success: function(data){
                        $.each(data.DATA, function(index, value) {

preguntado el 28 de agosto de 12 a las 12:08

this part " console.log(value.EMAIL);" give me undefined. How do I get all the email addresses returned from the Json call? -

2 Respuestas

The e-mails are within the DATA array; you should use data.DATA en lugar de solo data, which refers to the entire JSON object:

$.each(data.DATA, function(index, value) {

Respondido 28 ago 12, 12:08

I tried that but with the above code this gave me an error: TypeError: a is undefined - Prometeo

@Spike: You sure you don't have a typo? I don't reference any variable called a in the above code. Can you paste your new code? - Juan Carlos

edit code above. error is TypeError: a is undefined [Break On This Error] ...=[]),o&&(e=" "+e);while(e){k=!1;if(j=B.exec(e))e=e.slice(j[0].length),k=d.push({... - Prometeo

That's a jQuery error. Can you paste me the exact content of data? Is it a string or a JSON object? - Juan Carlos

That is because there is a null value provided to the $.each function. It is a jquery error, it more than likely comes from your JSON output than the jquery loop. - David Barker

Added below and issue was resolved. anyone know why?

type: "GET", dataType: "json",

Respondido 28 ago 12, 14:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.