AJAX Pagination with API generated records and Scroll EventListener

Posted by admin at January 5, 2017

We are going to paginate a table of records with AJAX. This application should load a set of new records, or a page, every time the user scrolls to the end of the page. Earlier on, we demonstrated how to paginate a table displaying local MySQL records using the First-Previous-Next-Last links, but for the sake of simplicity, we are going to be modifying a table of records generated from an API as demonstrated in this tutorial.

The full application can be found in this GitHub page. The application is written PHP and the API, implemented in Slim.

index.php

For the index file, we make sure we have our dependencies, the files needed to supply us with both PHP and JS function


// For establishing connection to the database
require('inc/conn.php');

...

// import CRUD support functions file
require('inc/support.php');

...

<?php //*********************************************READ ?>
    
    <?php include ('inc/r.php') ;?>
    
<?php //*********************************************READ ?>

...

<!--// main javascript function file-->
<script src="js/main.js"></script>

<!--// ajax calls file-->
<script src="js/ajax.js"></script>

Lets pick the dependencies one by one

The file conn.php, as usual would be


$host = 'DB_HOST';
$db = 'DB_NAME';
$user = 'DB_USER';
$pass = 'DB_PASS';

// setup the connection
$conn = mysql_pconnect($host, $user, $pass) or trigger_error(mysql_error(), E_USER_ERROR); 

// select the database
mysql_select_db($db, $conn);
   0 likes

Pages: 1 2 3 4 5 6


Suggested Read