请建议我为什么我的$(window).scrolltop()不适用于所有浏览器

时间:2019-01-30 08:32:55

标签: javascript jquery ajax

<script type="text/javascript">
$(document).ready(function(){
$(window).scroll(function(){
var lastID = $('.load-more').attr('lastID');
   if(($(window).scrollTop() == $(document).height() - $(window).height()) 
    && (lastID != 0)){
        $.ajax({
            url:"main_feed_ajax.php",
            method:"POST",
            data:'feed_id='+lastID,
            cache:false,
            beforeSend:function(){
                $('.load-more').show();
            },
            success:function(html){
                $('.load-more').remove();
                $('#postList').append(html);
            }
        });
    }
  }); 
 });
</script>

我有这段代码,无需滚动页面即可加载滚动数据。我的代码仅适用于某些浏览器。同样,它无法在使用谷歌浏览器,Firefox的手机和平板电脑上运行。只有它可以在Internet Explorer和某些Chrome浏览器上运行。因此,请建议我在此代码中需要进行哪些更改。 Index.php页面

<div id="postList">
<?php
// Include the database configuration file
require 'dbConfig.php';

// Get records from the database
$query = $db->query("SELECT * FROM user_post ORDER BY feed_id DESC LIMIT 
5");

if($query->num_rows > 0){ 
 while($row = $query->fetch_assoc()){
    $postID = $row["feed_id"];
    $feed_text = $row["feed_text"];
?>
<div class="list-item"><h4><?php echo $feed_text; ?></h4><img 
style="width:200px; height:200px;" src="car.jpg"></div>

<?php } ?>
<div class="load-more" lastID="<?php echo $postID; ?>" style="display: 
none;">
    <img src="loader.gif"/>
</div>
<?php } ?>
</div>

main_feed_ajax.php页面

<?php
if(!empty($_POST["feed_id"])){
//Include DB configuration file
$server_access_name="localhost";
$server_access_id="root";
$server_access_pass_code="";
$server_access_batabase_name="inkme"; 

// Create connection
$conn_server_link = mysqli_connect($server_access_name, $server_access_id, 
$server_access_pass_code, $server_access_batabase_name);
if(!$conn_server_link){
echo "!Ops, Unable to connect ";
}
//Get last ID
$lastID = $_POST['feed_id'];

//Limit on data display
$showLimit = 5;

//Get all rows except already displayed
$queryAll = $conn_server_link->query("SELECT COUNT(*) as num_rows FROM 
user_post WHERE feed_id < ".$lastID." ORDER BY feed_id DESC");
$rowAll = $queryAll->fetch_assoc();
$allNumRows = $rowAll['num_rows'];

//Get rows by limit except already displayed
$query = $conn_server_link->query("SELECT * FROM user_post WHERE feed_id < 
".$lastID." ORDER BY feed_id DESC LIMIT ".$showLimit);
 if($query->num_rows > 0){
 while($row = $query->fetch_assoc()){ 
    $postID = $row["feed_id"]; 
    $feed_text = $row["feed_text"]; 
    ?>


<div class="list-item"><h4><?php echo $feed_text; ?></h4><img 
style="width:200px; height:200px;" src="car.jpg"></div>
<?php } ?>
<?php if($allNumRows > $showLimit){ ?>
<div class="load-more" lastID="<?php echo $postID; ?>" style="display: 
none;">
    <img src="loader.gif"/>
</div>
<?php }else{ ?>
<div class="load-more" lastID="0">
   No more feeds
</div>
<?php }
}
else{ ?>
<div class="load-more" lastID="0">
    That's All!
</div>
<?php
}
}
?>

0 个答案:

没有答案