2

I took the code from this tutorial: https://www.senaidbacinovic.com/learn/jquery-infinite-scroll-tutorial Just changed the query and driver,but 'infinite scrollbar' posts the offset and limit only once.What might be the problem?

data.php

 $conn = odbc_connect("Driver=$driver;ServerNode=$host;Database=$db_name;CHAR_AS_UTF8=TRUE;", $username, $password, SQL_CUR_USE_ODBC);
    $start = $_POST['start'];
    $limit =$_POST['limit'];
    
    $sql='SELECT "DocNum"
    ,T0."customer"
 FROM tt where "DocNum" LIKE \'214%\' ORDER BY "DocNum" DESC LIMIT '.$limit.' OFFSET '.$start;
        $sql_exec=odbc_exec($conn,$sql);
        echo $sql;
        if (odbc_num_fields($sql_exec) > 0)
            {
            $response = "";

            while($data = odbc_fetch_array($sql_exec)) {
                $response .= '
                    <div>
                        <h2>'.odbc_Result($sql_exec,1).'</h2>
                        <p>'.odbc_Result($sql_exec,2).'</p>
                    </div>
                ';
            }

            exit($response);
        } else
            exit('reachedMax');
    }

index.html javascript

var start = 0;
        var limit = 21;
        var reachedMax = false;

        $(window).scroll(function () {
            if ($(window).scrollTop() == $(document).height() - $(window).height())
                getData();
        });

        $(document).ready(function () {
           getData();
        });

        function getData() {
            if (reachedMax)
                return;

            $.ajax({
               url: 'data.php',
               method: 'POST',
                dataType: 'text',
               data: {
                   getData: 1,
                   start: start,
                   limit: limit
               },
               success: function(response) {
                    if (response == "reachedMax")
                        reachedMax = true;
                    else {
                        start += limit;
                        $(".results").append(response);
                    }
                }
            });
        }

Edit: I changed nothing and now it works..I still wonder the reason though :)

wittream
  • 185
  • 11
  • Maybe `console.log($(window).scrollTop() == $(document).height() - $(window).height()))` – mplungjan Mar 21 '23 at 08:02
  • 1
    Thank you, it is working without doing anything, but I might try this next time.Having a lot of problems with infinite scrolbars. @mplungjan – wittream Mar 21 '23 at 08:03
  • I could not think of anything else. The code looked ok assuming the backend has more than 0+limit data – mplungjan Mar 21 '23 at 08:05
  • If it now works without you changing the code, it might be the browser cache. Some browsers do cache quite aggressively. Try refreshing your web page with Ctrl + R or Ctrl + F5 when loading edited frontend code. – Apodemus Mar 21 '23 at 08:07
  • It is doing the same thing again and I tried those but did't work @Apodemus – wittream Mar 21 '23 at 08:39
  • but yes it is about browsers, I used another browser and it worked again..... @Apodemus – wittream Mar 21 '23 at 08:41
  • [This question](https://stackoverflow.com/questions/3951187/javascript-file-not-updating-no-matter-what-i-do) might provide a useful solution. Caching can really be a pain sometimes. – Apodemus Mar 21 '23 at 09:07
  • thank you so much I'll check @Apodemus – wittream Mar 21 '23 at 11:25

0 Answers0