php - Is this the correct way to create a system of infinite-scrolling on my website? -


i've learned basics of sql, ajax , (object oriented) php, i've put use creating user build feed of information. however, @ present feed loads 20 recent posts in database (since loading of them @ once have negative impact on page load time).

i've decided trying implement system of infinite-scrolling (similar method used twitter , facebook) best solution problem, i'm not entirely sure how this.

i know first thing need function tell whether user has reached bottom of page. this, i've written following simple jquery:

  $(window).scroll(function() {      var scrollbottom = $(document).height() - $(document).scrolltop() - $(window).height();      if(scrollbottom < 200) {       // send ajax request     }   }); 

this bit of code should work, concerned risk of multiple ajax requests being sent server if user scroll multiple times before feed of posts has been updated.

i gather next thing need send off ajax request. naturally, script retrieves first 20 posts in database uses line of php/sql looking like

$query = "select * table desc limit 0,20"; 

i'm guessing need replace like

$query = "select * table desc limit " . $x . "," . $x+20; 

and create script keeps track of how many times ajax request has been sent off, , use determine variable $x ensure correct results fetched.

finally know i'd need create sort of callback function display posts had been fetched.

is correct (best) method use create system of infinite scrolling? also, how can alter jquery stop multiple requests being sent off?

yes correct, looking $query = "select * table desc limit " . $x . ", 20"; should next 20 rows , prevent more being gotten until $x updated.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -