jQuery的环槽JSON

问题描述:

我有一个循环槽JSON的问题,我的例子仅打印JSON的最后一块...jQuery的环槽JSON

JSON例如:

[{ 
"date": "May 15 2015 12:00:00:000AM", 
"link": "somelink1.pdf" 
}, { 
"date": "May 15 2015 12:00:00:000AM", 
"link": "somelink2.pdf" 
} 
] 

jQuery的一部分:

$.getJSON("PlaceOfMyJSON.php", function(response) { 
$.each(response, function (i, item) { 
$('#result').html(item.link);  
}); 
}); 

在现场JSON我有很多数据,但这个循环打印只有最后一个“链接”字段“somelink2.pdf”在我的div与ID结果...

这是因为你一遍又一遍覆盖你的html。

您需要更新从

$('#result').html(item.link); 

$('#result').append(item.link); 

仅供参考 - http://api.jquery.com/append/