Viewing file: load-comments.php (1.65 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<!-- Include JavaScript for loading more comments -->
<script>
document.addEventListener("DOMContentLoaded", function () {
const loadMoreButton = document.getElementById("loadMoreComments");
const commentsContainer = document.querySelector(".single-comments");
let page = 2; // Initial page number for loading more comments
loadMoreButton.addEventListener("click", function () {
const xhr = new XMLHttpRequest();
xhr.open("GET", "load-comments.php?id=<?php echo $id; ?>&page=" + page, true);
xhr.onload = function () {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
if (response.success && response.comments.length > 0) {
response.comments.forEach(function (comment) {
// Create and append new comment elements
const newComment = document.createElement("div");
newComment.classList.add("main");
newComment.innerHTML = `
<!-- ... (existing comment display code) -->
`;
commentsContainer.appendChild(newComment);
});
page++; // Increment the page number
} else {
// No more comments to load, hide the button
loadMoreButton.style.display = "none";
}
}
};
xhr.send();
});
});
</script>
|