我在我的網站上顯示項目,但不是一次顯示所有項目我正在使用「顯示更多」按鈕加載更多的項目與Ajax。但我似乎無法打印出我加載的項目的圖像,因爲它是一個斑點圖像。另一個問題是我不知道如何一次打印兩個項目,現在我一次只能加載一個項目。加載更多項目與blob圖像在它
// AJAX
$('#show-more').on("click", function(e){
e.preventDefault();
var lastID = $("#projects ul").children().last().attr('id');
$.ajax({
url: "ajax/show-more.php",
type: "POST",
data: {"lastID": lastID},
dataType:"json"
})
.done(function(msg){
if (msg.succes == true) {
$('#projects ul').append(
"<li class='project' id='"+msg.project.id+"'>"+
"<img src='data:image/jpg;base64, "+msg.project.image+"' alt='work'>"+
"<div class='mask fade'>"+
"<h4>"+msg.project.titel+"</h4>"+
"<p>"+msg.project.text+"</p>"+
"</div>"+
"</li>"
);
}
});
});
//顯示-more.php
<?php
try {
$db = mysqli_connect("localhost","root","","portfolio");
$lastID = $_POST["lastID"];
$sql = "SELECT * FROM work WHERE filter = 'webdesign' AND id < ".$lastID." ORDER BY id desc LIMIT 2";
$results = mysqli_query($db,$sql);
foreach ($results as $result) {
$response["project"] = $result;
}
$response["succes"] = true;
} catch (Exception $e) {
$response["succes"] = false;
}
echo json_encode($response);
?>
完美的作品!非常感謝你! –