-1
$(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.
        }
        });
    }
});

this is 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;
}
?>

i want to call a new ajax request and get 10 new names from table names everytime user scrolls down to bottom of scrollbar.

$name is the only variable from not_dat.php

M1X
  • 4,971
  • 10
  • 61
  • 123
  • possible duplicate of [How to implement an endless/infinite scroll within a DIV in Javascript/jQuery](http://stackoverflow.com/questions/15181286/how-to-implement-an-endless-infinite-scroll-within-a-div-in-javascript-jquery) – NDM Sep 25 '13 at 12:13

1 Answers1

1

Try this:

$(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);
    }
    });
  }
});
Gurminder Singh
  • 1,755
  • 16
  • 19
  • Didn't understand you. – Gurminder Singh Sep 25 '13 at 12:39
  • Don't _echo_ in while loop, rather add names to a _collection_ and _echo the collection_ outside the loop. Also you'll have to send some additional parameters like **start** and **end** to server. Then limit the results with _limit_ keyword in MySQL. – Gurminder Singh Sep 25 '13 at 12:47
  • yes but how to show 10 of $name variable while scrolling and so on? – M1X Sep 25 '13 at 12:49