I would like if I scroll bottom of .dropdown-menu, load more 7 row in database. I don't know why not using this script. I'm using bootstrap css and js. I tried the bootstrap-select.js with live search, but I have 2000 row in "town" database, and bootstrap-select doesn't have "load more" function.
<meta charset="utf-8">
<link rel="stylesheet" href="bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="bootstrap.js"></script>
<style>.dropdown-menu{height: auto;max-height: 150px;overflow-x:hidden;}</style>
<div class="dropdown">
    <input class="dropdown-toggle" data-toggle="dropdown" id="live" placeholder="Town">
    <ul class="dropdown-menu"></ul>
</div>
<script>
$(document).ready(function () {
    var limit = 7;
    var start = 0;
    var action = 'inactive';
    var location = $('#live').val();
    $('.dropdown-menu').hide();
    function search() {
        var limit = 7;
        var start = 0;
        var action = 'inactive';
        var location = $('#live').val();
        if (location != '') {
            $('.dropdown-menu').show();
            $.ajax({
                url: "search.php",
                type: "POST",
                data: {location:location, limit:limit, start:start},
                cache: false,
                success: function(data) {
                    $('.dropdown-menu').html(data);
                    if(data == '') {
                        $('#load').text('No more data.');
                        action = 'active';
                    } else {
                        $('#load').text('Loading...');
                        action = 'inactive';
                    }
                    $('.dropdown-menu li a').click(function() {
                        $('.dropdown-menu li a').removeClass('active');
                        $(this).addClass('active');
                        var active = $('li a.active').html();
                        $('#live').val(active);
                    });
                }
            });
        } else {
            $('.dropdown-menu').hide();
            $('.dropdown-menu li a').removeClass('active');
        }
    };
    if (action == 'inactive') {
        action = 'active';
        $('#live').on('keyup change', search);
    }
    $(window).scroll(function(){
        if ($(window).scrollTop() + $(window).height() > $(".dropdown-menu").height() && action == 'inactive') {
            action = 'active';
            start = start + limit;
            setTimeOut(function(){
                $('#live').on('keyup change', search);
            }, 1000);
        }
    });
});
</script>
search.php:
<?php
$connect = mysqli_connect("localhost", "root", "", "mydb");
$location = $connect->real_escape_string($_POST["location"]);
if (isset($_POST["location"])) {
    $data = mysqli_query($connect, "SELECT * FROM towns WHERE town LIKE '%".$location."%' ORDER BY id LIMIT ".$_POST["start"].", ".$_POST["limit"]."");
    $data_count = mysqli_num_rows($data);
    if ($data->num_rows === 0) {
        echo '<li>No data!</li>';
    } else {
        while ($row = mysqli_fetch_array($data)) {
            echo '<li><a href="#">'.$row["town"].'</a></li>';
        }
        echo '<div id="load"></div>';
    }
}
?>
 
    