title: infinity scroll: Load all data from database and scroll to show more
body: <p>I am using infinity scroll in my project. First it will fetch few records from MySQL database and show on page. Once page scroll down it make ajax query to server and load more data.</p>
  
  <p>Is it possible to fetch all data at once from mysql database in json format and then perform load more on client side. So, basically I want no ajax request to database.</p>
  
  <p>Here is the code which is working fine if I make ajax request on page scroll.</p>
  
  <pre><code>flag = true;
  $(window).scroll(function() {
      if($(window).scrollTop() + $(window).height() == $(document).height()){
          first = $('#first').val();
          limit = $('#limit').val();
          no_data = true;
          if(flag &amp;&amp; no_data){
              flag = false;
              $('#loader').show();
              $.ajax({
                  url : 'ajax_html.php',
                  method: 'post',
                  data: {
                     start : first,
                     limit : limit
                  },
                  success: function( data ) {
                      flag = true;
                      $('#loader').hide();
                      if(data !=''){
  
                          first = parseInt($('#first').val());
                          limit = parseInt($('#limit').val());
                          $('#first').val( first+limit );
                          $('#timeline-conatiner').append( '&lt;li class="year"&gt;'+year+'&lt;/li&gt;');
  
                          $('#timeline-conatiner').append( data );
                          year--;
                      }else{
                          alert('No more data to show');
                          no_data = false;
                      }
                  },
                  error: function( data ){
                      flag = true;
                      $('#loader').hide();
                      no_data = false;
                      alert('Something went wrong, Please contact admin');
                  }
              });
          }
  
  
      }
  }); 
  </code></pre>