滚动时的 AJAX 请求


ajax request while scrolling

$(window).scroll(function() {
    if( $(window).scrollTop() == $(document).height() - $(window).height()) {
        $.ajax({
        type: "GET",
        url: "not_data.php",
        data: dataString,
        success: function my_func () {
           // display 10 new names.
        }
        });
    }
});

这是not_data.php

<?php
$name_query=mysql_query("SELECT name FROM  names");
        while($run_query = mysql_fetch_assoc($name_query)) {
            $name = $run_query['name'];
            echo $name;
}
?>

我想调用一个新的 Ajax 请求,并在每次用户向下滚动到滚动条底部时从表名中获取 10 个新名称。

$name是not_dat.php中唯一的变量

试试这个:

$(window).scroll(function() {
  if( $(window).scrollTop() == $(document).height() - $(window).height()) {
    $.ajax({
    type: "GET",
    url: "not_data.php",
    data: dataString,
    success: function(data) {
       var htm = null;
       for(var i=0; i<data.length; i++) {
          htm += "<div>"+data[i]+"</div>";
       }
       $("container-div-id").append(htm);
    }
    });
  }
});