我一直在使用这段代码,它最初来自:Infinite Scroll Tutorial (尽管我更新了已弃用的 sql 对其进行了编辑)
我遇到的问题是 ajax 没有触发/工作。我在之前放置了警报,$.ajax
以便我知道它何时触发,并且当我点击页面底部(或靠近它)时它会触发,就像它应该的那样。但是 ajax 没有产生任何信息,我不知道为什么。
emptyk.php:
<script src="../jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
$(window).scroll(function(){
$('#a1').text($(window).scrollTop());
$('#a2').text($(window).height());
$('#a3').text($(document).height());
});
var page = 1;
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(document).height() - 500) {
page++;
var data = {
page_num: page
};
var actual_count = "<?php echo $actual_row_count; ?>";
if((page-1)* 10 > actual_count){
//$('#load').show();
}else{
alert("Ajax active");
$.ajax({
type: "POST",
url: "emptykdata.php",
data:data,
success: function(res) {
$("#result").append(res);
}
});
}
}
});
});
</script>
<div id="a1">Wut</div>
<div id="a2">Wut</div>
<div id="a3">Wut</div>
<div id="result"></div>
空kdata.php
<?php
include '../includes/connect.php';
$requested_page = $_POST['page_num'];
$set_limit = (($requested_page - 1) * 10) . ",10";
$resultstmt = mysqli_prepare($connection, "SELECT * FROM products ORDER BY Mminppu ASC LIMIT $set_limit");
mysqli_stmt_execute($resultstmt);
$result = mysqli_stmt_get_result($resultstmt);
$add = mysqli_num_rows($result);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$_SESSION['PID'] = $row['PID'];
include '../includes/baseproductlist.php';
}
//echo $html;
?>
有任何想法吗?
更新:
我检查了 javascript 控制台,它有以下错误消息:
GET http://localhost/Triiline2/jquery-1.10.2.min.map 404 (Not Found)