【发布时间】:2017-01-10 18:25:19
【问题描述】:
我很难处理 ajax 对象传回。我试图遍历每个对象并从每个对象输出每个数据值。
AJAX 调用:
$.ajax({
type: "POST",
url: "sample.url",
data: JSON.stringify(SDdata),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
console.log(data)
$('#SD_Title').html(data.PagedData[1].SD_Plan_Name);
$.each(data, function() {
$.each(data, function(index) {
console.log(data.PagedData[index].SD_Plan_Name);
$('#SD_Content').html(data.PagedData[index]);
});
});
},
failure: function(errMsg) {
alert(errMsg);
}
});
到 console.logs 继续抛出 undefined??
我正在接收的数据
Array[3]
0:Object
SD_Plan_CreatedDate : "11/01/2016"
SD_Plan_ID : 15
SD_Plan_Name : "Jeff Harris D1 Replacement"
SD_Plan_Status : 3
SD_Plan_TotalCost : 75219.56
SD_Plan_UnitCount : 268
1:Object
2:Object
编辑 1:
Console.log(data) output
Object
PagedData:Array[3]
0:Object
SD_Plan_CreatedDate:"11/01/2016"
SD_Plan_ID:15
SD_Plan_Name:"Jeff Harris D1 Replacement"
SD_Plan_Status:3
SD_Plan_TotalCost:75219.56
SD_Plan_UnitCount:268
__proto__:Object
1:Object
2:Object
length:3
__proto__:Array[0]
Total:3
__proto__:Object
【问题讨论】:
-
也许可以学习一些基本的调试技能,这样就不必每次不确定数据结构时都跑到堆栈溢出
-
console.log(data) -
不开玩笑,我知道如何调试 lol
-
我认为你应该去 console.log(data.SD_Plan_Name);而不是 console.log(data.PagedData[index].SD_Plan_Name);
-
@codenut 抛出未定义的我试图循环遍历数组,然后遍历对象并输出每个对象的 SD_Plan_Name
标签: javascript jquery ajax coldfusion