此脚本通过向下滚动页面来加载更多SQL记录。这在计算机上运行良好,但在iPhone上它无法正常工作,在Android上这根本不起作用。那么为什么这在计算机上完美运行,但它在移动设备上无法正常工作,这意味着在那些移动设备上它不会加载更多的SQL记录。任何代码建议将非常感激。
的index.php
<!DOCTYPE html>
<html>
<head>
<style>
#load-more-button {
width: 100px;
margin: auto;
display: block;
}
.results-container {
width: 350px;
margin: auto;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function (){
/*<load more records by page scrolling script>*/
//<settings define
var start = 0;
var limit = 10;
//
//Call the ajax request on page load
getData();
//
//load more records by page scrolling
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()){
getData();
}
});
//
/*<function>*/
function getData() {
//settings variable
var settings = {
getData: 1,
start: start,
limit: limit
};
//
//result variable
var result= function(response) {
start += limit;
$(".results-container").append(response);
}
//
//request
$.ajax({
url: 'data.php',
type: 'POST',
dataType: 'text',
data: settings,
success: result
});
}
/*</function>*/
/*</load more records by page scrolling script>*/
});
</script>
</head>
<body>
<div class="results-container"></div>
</body>
</html>
data.php
<?php
$servername='localhost';
$username='x';
$password='1234';
$db_name= 'x';
$connect = new mysqli($servername,$username,$password,$db_name);
$start = $connect->real_escape_string($_POST['start']);
$limit = $connect->real_escape_string($_POST['limit']);
$query = "SELECT*FROM user_details LIMIT $start, $limit";
$result= $connect->query($query);
?>
<style>
#number{
background-color: gold;
color: black;
border-radius: 100%;
padding: 5px;
}
h2{
display: inline-block;
}
</style>
<?php while($row = $result->fetch_assoc()) { ?>
<h2 id='number' ><?php echo $row['user_id']; ?></h2>
<h2><?php echo $row['username']; ?></h2>
<p><?php echo $row['password']; ?></p>
<?php } ?>