javascript scroll load more code example
Example 1: jquery infinite scroll
$(window).scroll(function () {
if ($(document).height() - $(this).height() == $(this).scrollTop()) {
$.ajax({
type: "POST",
url: "index.aspx/GetData",
contentType: "application/json; charset=utf-8",
data: '',
dataType: "json",
success: function (msg) {
if (msg.d) {
$(".container").append(msg.d);
}
},
error: function (req, status, error) {
alert("Error try again");
}
});
}
});
Example 2: ajax call to load a page on scrolling
.container{
width: 55%;
margin: 0 auto;
border: 0px solid black;
padding: 10px 0px;
}
.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{
color: blue;
text-decoration: none;
letter-spacing: 1px;
font-size: 16px;
}
Example 3: ajax call to load a page on scrolling
<?php
$host = "localhost";
$user = "root";
$password = "";
$dbname = "tutorial";
$con = mysqli_connect($host, $user, $password,$dbname);
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}