Используйте следующий код, который я привел вам простой пример:
<html>
<head>
</head>
<body>
<div id="userData">
</div>
</body>
</html>
НА НАГРУЗКЕ
$(window).scroll(function () {
if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
var last_id = $("#userData a:last-child").attr('id');
if(last_id == "" || last_id == undefined)
{
last_id=0;
}
loadMoreData(last_id);
}
});
**
ФУНКЦИЯ НАГРУЗКА БОЛЬШЕ ДАННЫХ
function loadMoreData(last_id) {
$.ajax(
{
url: 'get_results.php?last_id=' + last_id ,
type: "get",
beforeSend: function () {
$('.ajax-load').show();
}
})
.done(function (data) {
$('.ajax-load').hide();
$("#userData").append(data);
})
.fail(function (jqXHR, ajaxOptions, thrownError) {
console.log('server not responding...');
});
}
На контроллере вы получаете идентификатор и выбираете данные, превышающие текущий полученный идентификатор
<?php
if(isset($_GET['last_id']))
{
$conn = mysqli_connect("localhost", "id5757217_testsql01", "9977553311", "id5757217_testsql1");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if($lastId!=0){
$sql = ("SELECT * FROM insertion where id < '" . $lastId . "' ORDER BY id DESC LIMIT 5");
}else{
$sql = ("SELECT * FROM insertion ORDER BY id DESC LIMIT 5");
}
$result = $conn->query($sql);
while ( $row = $result-> fetch_array()) {
echo "<div id = 'load'>";
echo "<div id = 'load1'>" . $row['Title'] . "</div>";
echo "<div id = 'load2'>" . $row['Description'] . "</div>";
echo "<div id = 'get'>" . "<a href = '" . $row['Link'] . "' target = '_blank' id = '" . $row['id'] . "'> Get This file </a> </div>";
echo "</div>";
}
exit();
}
?>