爲了處理數據,我使用了for循環,但沒有正確顯示。我真的被困住了。數據來自另一個腳本,但問題在for循環中。我錯過了什麼?Json Data Forloop問題
$.ajax({
type:"POST",
url: "more.php",
data:"&max_id="+maxid, //Forms name
datatype: "json",
success: function(data, textStatus, xhr) {
data = JSON.parse(xhr.responseText);
//var image = data.images;
for (var i = 0, len = data.length; i < len; i++) {
var image = data.images;
var likes = data[i].likes[i];
var comments = data[i].comments[i];
var nextid=data[i].next_id;
$(".row").append("<div class='col-md-2 col-sm-3'><div class='thumbnail'><img src='"+image+"' style='width: 100%;' alt='Gallery Image'><p><br/> Likes:"+likes+" <br/> Comments: "+comments+" </p></div></div>");
}
}
});
我的JSON數據:
{
"next_id":"1075182757212925396_588379938",
"images":[
"xyz.com",
"abc.com",
"def.com"
],
"likes":[
26,
21,
29
],
"comments":[
0,
4,
0
]
}
你是否獲取數據作爲數組.. ..?或者您正在獲取僅在此處發佈的數據..? – sunil