ajax call to load a page on scrolling

$(document).ready(function(){
 
 $(window).scroll(function(){
 
  var position = $(window).scrollTop();
  var bottom = $(document).height() - $(window).height();

  if( position == bottom ){

   var row = Number($('#row').val());
   var allcount = Number($('#all').val());
   var rowperpage = 3;
   row = row + rowperpage;

   if(row <= allcount){
    $('#row').val(row);
    $.ajax({
     url: 'fetch_details.php',
     type: 'post',
     data: {row:row},
     success: function(response){
      $(".post:last").after(response).show().fadeIn("slow");
     }
    });
   }
  }

 });
 
});

3.57
7
Phoenix Logan 186120 points

                                    &lt;?php

$host = &quot;localhost&quot;; /* Host name */
$user = &quot;root&quot;; /* User */
$password = &quot;&quot;; /* Password */
$dbname = &quot;tutorial&quot;; /* Database name */

$con = mysqli_connect($host, $user, $password,$dbname);

// Check connection
if (!$con) {
  die(&quot;Connection failed: &quot; . mysqli_connect_error());
}

3.57 (7 Votes)
0
3
1
Awgiedawgie 440220 points

                                    var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();

3 (1 Votes)
0
3.88
8
Phoenix Logan 186120 points

                                    CREATE TABLE `posts` (
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `description` text NOT NULL,
  `link` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

3.88 (8 Votes)
0
0
10
Krish 100200 points

                                    &lt;div class=&quot;container&quot;&gt;

&lt;?php

 include &quot;config.php&quot;;

 // Row per page
 $rowperpage = 3;

 // counting total number of posts
 $allcount_query = &quot;SELECT count(*) as allcount FROM posts&quot;;
 $allcount_result = mysqli_query($con,$allcount_query);
 $allcount_fetch = mysqli_fetch_array($allcount_result);
 $allcount = $allcount_fetch['allcount'];

 // select first 3 posts
 $query = &quot;select * from posts order by id asc limit 0,$rowperpage &quot;;
 $result = mysqli_query($con,$query);

 while($row = mysqli_fetch_array($result)){

   $id = $row['id'];
   $title = $row['title'];
   $content = $row['description'];
   $shortcontent = substr($content, 0, 160).&quot;...&quot;;
   $link = $row['link'];
 ?&gt;

   &lt;div class=&quot;post&quot; id=&quot;post_&lt;?php echo $id; ?&gt;&quot;&gt;
     &lt;h1&gt;&lt;?php echo $title; ?&gt;&lt;/h1&gt;
     &lt;p&gt;
       &lt;?php echo $shortcontent; ?&gt;
     &lt;/p&gt;
     &lt;a href=&quot;&lt;?= $link ?&gt;&quot; target=&quot;_blank&quot; class=&quot;more&quot;&gt;More&lt;/a&gt;
   &lt;/div&gt;

 &lt;?php
 }
 ?&gt;

 &lt;input type=&quot;hidden&quot; id=&quot;row&quot; value=&quot;0&quot;&gt;
 &lt;input type=&quot;hidden&quot; id=&quot;all&quot; value=&quot;&lt;?php echo $allcount; ?&gt;&quot;&gt;

&lt;/div&gt;

0
0
4.5
2
Awgiedawgie 440220 points

                                    .container{
 width: 55%;
 margin: 0 auto;
 border: 0px solid black;
 padding: 10px 0px;
}

/* post */
.post{
 width: 97%;
 min-height: 200px;
 padding: 5px;
 border: 1px solid gray;
 margin-bottom: 15px;
}

.post h1{
 letter-spacing: 1px;
 font-weight: normal;
 font-family: sans-serif;
}


.post p{
 letter-spacing: 1px;
 text-overflow: ellipsis;
 line-height: 25px;
}

/* more link */
.more{
 color: blue;
 text-decoration: none;
 letter-spacing: 1px;
 font-size: 16px;
}

4.5 (2 Votes)
0
3
1
Awgiedawgie 440220 points

                                    &lt;?php

// configuration
include 'config.php';

$row = $_POST['row'];
$rowperpage = 3;

// selecting posts
$query = 'SELECT * FROM posts limit '.$row.','.$rowperpage;

$result = mysqli_query($con,$query);

$html = '';

while($row = mysqli_fetch_array($result)){
  $id = $row['id'];
  $title = $row['title'];
  $content = $row['description'];
  $shortcontent = substr($content, 0, 160).&quot;...&quot;;
  $link = $row['link'];
  // Creating HTML structure
  $html .= '&lt;div id=&quot;post_'.$id.'&quot; class=&quot;post&quot;&gt;';
  $html .= '&lt;h1&gt;'.$title.'&lt;/h1&gt;';
  $html .= '&lt;p&gt;'.$shortcontent.'&lt;/p&gt;';
  $html .= '&lt;a href=&quot;'.$link.'&quot; target=&quot;_blank&quot; class=&quot;more&quot;&gt;More&lt;/a&gt;';
  $html .= '&lt;/div&gt;';

}

echo $html;

3 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
Load data while scrolling page down with jQuery Ajax ajax load on scroll on scroll load more inside a div jquery load more on scroll js load data just before you scrolled to the bottom jquery auto load more load page with scroll down loading on scrolling javascript load as you scroll jquery load more scroll to bottom load more ajax detect bottom page scroll down load more jquery scroll and load jquery how to make datastream scroll upwards jquery window scroll for load how to dea with jquery ajax and scrolling page scroll loading jquery scroll contant load scroll load more jquery scroll bottom jquery ajax example show more records on scrolling ajax call to load products jquery relative scrolling load content when scroll down can js auto load when scroll down canjs how to onscroll load using ajax to prevent page refresh onscroll event load more load data on scroll jquery loading fetch data jquery on scroll lazy loading fetch data jquery on scroll on scroll adding data jquery scroll to load more content pagination with jquery on scroll load data load more Content On Scroll Down - Scroll Pagination site:stackoverflow.com load on scroll jquery how to get all content to load on scroll loading on scroll jquery load url data on a div scroll using jquery ajax load content on scroll down how to dynamically fetch post in jquery and load more as user goes down jquery load more automatically load more data on scroll javascript div tag load more text on scroll load mor text on scroll load list items when scroll to the bottom js scroller auto load in jquery load ajax if page scrolled 80% scroll all the way to the bottom trigger ajax call autoload pagination jquery user scroll down and load content javascript scroll load more load more data on scroll dropdown javascript js ajax list with 100 list scroll on load on dropdown js ajax list with 100 list scroll on load on scroll load more jquery load more on scroll up javascript load more on scroll up load more on scroll load more content when footer appearing javascript jquery show more control the scroll js ajax fetch on scroll on scroll load 100 after 100 in dropdown javascript how to make ajax call based on scrolling in javascript how to make ajax call based on scrolling load more scroll to bottom javascript load more scroll javascript javascript load page on scroll down how to fetch data while scroll javascript scroll to load more load as you scroll functionality javascript load more on scroll to bottom of div load more when scroll to bottom jquery jquery load more below scroll down to load more load data on div scroll using jquery how to execute ajax when scrolling down jquery ajax load more scroll load content on page scroll jquery onadding more data to page by js page wil scroll to down load more data on scroll javascript js load records with scrollbar scroll auto load ajax load on scroll scroll before load more page scroll loading with ajax js load on scroll jquery scroll ajax load content load more records with on scroll javascirp jquery scroll down ajax jquery load page on scroll javascript load more on scroll load on scroll in jquery
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source