简体   繁体   中英

Ajax infinite scrolling not loading

So in my index.php file i have this:

<script src="jquery-1.12.3.js"></script>
    <script>
        $(window).scroll(function() {
           var load = 0;
           if($(window).scrollTop() + $(window).height() == $(document).height()) {
               load++;
               $.POST("scripts/myload.php",{load:load},function(data){
                 $.('photoclass').append(data);
               })
           }
        });
      </script>

and in my "myload.php" file i have this

$query = $handler->query("SELECT * FROM photo LIMIT ".$load.",5");
while($photo = $query->fetch()){
  echo '<center><h1 class="ptitle">'.$photo['PhotoTitle'].'</h1></center>';
  echo '<center><img src="UserPhotos/'.$photo['Photo'].'"></center>';
}

The problem is that it won't load in my index file the rest... Thanks in advance.

change your jquery code.

$.('photoclass').append(data); to

$('.photoclass').append(data); or $('#photoclass').append(data);

putting "." or "#" depends on class or id.

for example :

<div class="photoclass"> </div> then use $('.photoclass').append(data); otherwise $('#photoclass').append(data);

and in your php file make sure you are saving post value to variable.

like this $load=$_POST['load']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM