0

我正在尝试循环我在查询中收到的键/值对并控制台输出电子邮件地址。我做错了什么?

我收到的 JSON...

{"ERRORS":[],"DATA":[{"INCENTIVEID":"1","CREATED":"","EMAIL":"email","RECIPIENTID":"1","NAME":"glyn","ACTIVE":0,"MODIFIED":"","MOBILE":"11111111111"},{"INCENTIVEID":"1","CREATED":"","EMAIL":"eee","RECIPIENTID":"2","NAME":"edem","ACTIVE":0,"MODIFIED":"","MOBILE":"11111111111"}],"MESSAGES":[]}

当前脚本

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

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

2 回答 2

3

电子邮件在DATA数组内;您应该使用data.DATA而不是 just data,它指的是整个 JSON 对象:

$.each(data.DATA, function(index, value) {
  console.log(value.EMAIL);
});
于 2012-08-28T11:55:39.800 回答
0

在下面添加,问题已解决。有谁知道为什么?

类型:“GET”,数据类型:“json”,

于 2012-08-28T13:22:30.300 回答