【发布时间】:2010-02-23 14:58:52
【问题描述】:
我对 Ajax 和 JSON 还很陌生,并试图让它工作,但似乎无法掌握它。
如何在ajax中调用json并显示json文件中的所有信息?
这是我的 json 文件
{
posts: [{
"image": "images/bbtv.jpg",
"alter": "BioBusiness.TV",
"desc": "BioBusiness.TV",
"website": "http://andybudd.com/"
}, {
"image": "images/grow.jpg",
"alter": "Grow Staffing",
"desc": "Grow Staffing",
"website": "http://growstaffing.com/"
}]
}
和我正在使用的 ajax 函数
$.ajax({
type: "GET",
url: "category/all.js",
dataType: "json",
cache: false,
contentType: "application/json",
success: function(data) {
$.each(data.posts, function(i, post) {
$('#folio').html('<ul><li><div class="boxgrid captionfull"><img src="' + post.image + '" alt="' + post.alter + '" /><div class="cover boxcaption"><p>' + post.desc + '</p><a href="' + post.website + '" target="_blank">More Work</a></div></div></li></ul>');
});
initBinding();
},
error: function(xhr, status, error) {
alert(xhr.status);
}
});
由于某种原因,它只显示最后一项......
对正确方向的任何帮助都会很棒。
谢谢!
【问题讨论】: