Load more data on page scroll using jQuery, Ajax and Codeigniter

Pagination is one of the most frequently used features for web applications. Pagination is the process of dividing a document into discrete pages. In this post, We have share how to implement Load more data on page scroll using jQuery, Ajax and Codeigniter.
Whenever the user scrolls from top to the bottom of the page the user gets more results from database automatically. This is a very simple example, you can just copy paste and change according to your requirement.
Before started to implement the Load more data on page scroll using jQuery, Ajax and Codeigniter, look files structure:
  • load-data-on-page-scroll-using-jquery-and-codeigniter
    • application
      • config
        • autoload.php
        • database.php
        • constants.php
        • routes.php
      • controllers
        • News.php
      • models
        • News_model.php
      • views
        • news
          • index.php
          • render.php
        • templates
          • header.php
          • footer.php
    • system
    • index.php
    • assets
      • css
        • style.css
Step 1: Create the database and Table
For this tutorial, you need a MySQL database with the following table:
Step 2: Create Model
Create a model file named News_model.php inside “application/models” folder.
Step 3: Create controllers
Create a controllers file named News.php inside “application/controllers” folder.
  • The News controller handles the calendar process.
  • __construct() – Loads the required library, helper and model.
  • index() – load news data.
  • loadData() – Ajax request and get news data.
Step 4:Create a view(header)
Create a view file named header.php inside “application/views/templates” folder.
This view contains the header section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header section.
Step 5: Create a view(footer)
Create a view file named footer.php inside “application/views/templates” folder.
This view contains the footer section of the webpage.
Step 6: Create views
Create a views file named index.php inside “application/views/news folder.
Step 7: Create views
Create a views file named render.php inside “application/views/news folder.
Step 8: Make Ajax Request and Load Data with Pagination
We will also need to use jQuery code in views index.php in "application/views/news" directory to load pagination and make Ajax request to load more records.