-2

I've been trying to get infinite scrolling working on my website - and a lot of it is working (fetching from DB etc), but the infinite scroll part isn't. I've been following this tutorial (https://codeamend.com/blog/infinite-scrolling-on-php-website-using-jquery-and-ajax-with-example/) but there seems to be a problem with the Javascript - which can best be described as I don't understand it or what is going on…

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script>
$(window).scroll(function() {
    if($(window).scrollTop() + $(window).height() >= $(document).height()) {
        var last_id = $(".postid:last").attr("Item_ID");
        loadMore(last_id);
    }
});

function loadMore(last_id){
  $.ajax({
      url: 'load_more.php?last_id=' + last_id,
      type: "get",
      beforeSend: function(){
          $('.ajax-load').show();
      }
  }).done(function(data){
      $('.ajax-load').hide();
      $("#post-data").append(data);
  }).fail(function(jqXHR, ajaxOptions, thrownError){
      alert('server not responding...');
  });
}
</script>

There's an error on line $(window).scroll(function() which is Can't find variable: $. Can anyone explain what's going on here, and how I can fix it?

headbanger
  • 1,038
  • 1
  • 11
  • 32

0 Answers0