我正在尝试循环我在查询中收到的键/值对,并控制掉电子邮件地址。我做错了什么?
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);
}
});
}
});
});
答案 0 :(得分:3)
电子邮件在DATA
数组内;你应该使用data.DATA
而不仅仅是data
,它引用整个JSON对象:
$.each(data.DATA, function(index, value) {
console.log(value.EMAIL);
});
答案 1 :(得分:0)
在下面添加,问题已解决。有谁知道为什么?
输入:“GET”, dataType:“json”,