我正在尝试使用轮播创建一个滑块,我希望每个幻灯片显示4个项目。数据将以json
格式从数据库表中传输。现在我有这个PHP脚本但我想我必须改变一些部分来完成这项工作。
$stmt_select = $conn->prepare("SELECT * FROM `gifts` LIMIT 0,4;");
$stmt_select->execute();
if($stmt_select->rowCount() > 0) {
$json = array();
while ($row_select = $stmt_select->fetch()){
$json[] = array(
'image' => $row_select['image'],
'title' => $row_select['title'],
'description' => $row_select['description']
);
}
echo json_encode($json);
}
这是加载json的脚本
$.ajax({
url: 'ajax_json.php',
type: 'POST',
data: {get_param: 'value'},
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function(data) {
// check with console
console.log(data);
$.each(data, function(index, item) {
$('#output').append('<li class="caption"><div class="col-md-3"><div class="item_img"><img src="' +item.image+ '" /></div><div class="item_title">"' +item.title+ '"</div><div class="item_descr">'+ item.description +'</div></div></li>');
});
}
});
任何想法我该如何实现?