在我的PHP文件(data.php)中,我有:
$sth = $dbh->query("SELECT * from posts LIMIT 20");
$articles_row = $sth->fetchAll(PDO::FETCH_ASSOC);
$articles_array[] = $articles_row;
echo json_encode($articles_array);
以下是我在jQuery中的内容:
$.get("http://projects.dev/projects/json_training/data.php", function(data) {
jQuery.each(data, function() {
$(".articles").append('<div class="item">' + data[0][0]['post_title'] + '</div>');
});
}, "json");
但我只能打印一个结果因为这个数据[0] [0] ['post_title'] 不幸的是,我不能让jQuery.each以某种方式工作来打印JSON数组的所有结果,我不能从数据中删除索引[0] [0] ['post_title']
这是JSON输出:
[[{"post_id":"115","post_title":"Another High Tech Epic Phone","post_author":"AuthorName","post_subtitle":"I made it up my yep!","post_published_date":"2014-04-16 18:32:33","post_views":"49","post_photo":"Desert_Landscape_1","post_photo_caption":"dasdasdsaasdas","post_content":"dasdasddasd basdbhsajbsd djshbsj dasj bdasjh","featured":"1","category_id":"1","post_tags":"ddbsjhs, dasdasd, dasdsa","meta_description":"dssdfndsfn sdjfn djsk","meta_keywords":"fdsfsdfs, fsdfsdfds, fsdfds"}...
您对我如何打印所有结果有什么想法吗? 提前谢谢!