title: Displaying huge amount of data from database gradually using AJAX - LARAVEL
body: <p>I'm using laravel to fetch huge amount of data from database (100mil++ data), but it was giving me error which is timeout because loading the data is too long, and i want to use AJAX to append the data in Laravel view gradually by calling the controller, and then the controller fetch the data using query with LIMIT, so the view will gradually displaying data in accordance with the limited data, so it wont be timeout</p>
  
  <p>controller :</p>
  
  <pre><code>public function index(){
      return view('users.index',compact('users'));
  }
  
  public function loadAjax(){
      // print_r('expression');
      $counter = Input::get('counter');
      $users = User::take(1)-&gt;skip($counter)-&gt;get();
      return json_encode($users);
  }
  </code></pre>
  
  <p>jquery and AJAX:</p>
  
  <pre><code>&lt;script&gt;
    var ctr = 0;
    window.onload = function () {
      getData();
    };
  
    window.setInterval(function () {
      ctr++; //increase the data offset
      getData();
    }, 1000);
  
   function getData() {
          jQuery(document).ready(function() {
              jQuery.ajax({
                  url: "users/ajax",
                  type: 'GET',
                  data: {counter : ctr},
                  dataType: "json",
                  success: function(data) {
                      console.log(data.users);
                      for(var i =0; i &lt; data.users.length; i++) {
                          var htm = '';
                          htm += '&lt;tr id="inside"&gt;'
                          htm +=  '&lt;td&gt;'+data.users[i].id+'&lt;/td&gt;';
                          htm +=  '&lt;td&gt;'+data.users[i].name+'&lt;/td&gt;';
                          htm +=  '&lt;td&gt;'+data.users[i].email+'&lt;/td&gt;';
                          htm += '&lt;/tr&gt;'
                          $("#inside").append(htm);
                      }
                  },
                  error: function(data) { 
                  }
              });
          });
      }  
  &lt;/script&gt;
  </code></pre>
  
  <p>routes :</p>
  
  <pre><code>Route::get('users/ajax','UserController@loadAjax');
  </code></pre>
  
  <p>the problem is i'm new with ajax and idk if my method is the right way</p>