title: How to output json
body: <p>I have this PDO statement:</p>
  
  <pre><code>  public static function ajax($start = 0){
      $limit = 4;
          $database = DatabaseFactory::getFactory()-&gt;getConnection();
  
      $sql = 'SELECT * FROM MOCK_DATA ORDER BY date DESC LIMIT :start, :limit';
      $query = $database-&gt;prepare($sql);
      $query-&gt;bindValue(':start', intval($start), PDO::PARAM_INT);
      $query-&gt;bindValue(':limit', intval($limit), PDO::PARAM_INT);
      $query-&gt;execute();
  
          if($query-&gt;rowCount() &lt; 0){
              return false; 
          } 
  
          $rowcount = $query-&gt;rowCount();
          $data = new StdClass();
          $data-&gt;count = $rowcount;
          $data-&gt;content = $query-&gt;fetchAll();
  
          return json_encode($data);
      }
  </code></pre>
  
  <p>(Notice that i add a extra column(?) to the stdClass, <code>count</code>)</p>
  
  <p>That returns this json: </p>
  
  <pre><code>   {"mockup":"{\"count\":4,\"content\":
  [{\"id\":\"408\",\"email\":\"jbrooksbb@theglobeandmail.com\",\"ip_address\":\"128.42.226.235\",\"date\":\"2015-10-05\",\"text\":\"Cras in purus eu magna vulputate luctus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.\"},
  {\"id\":\"832\",\"email\":\"wlanen3@ning.com\",\"ip_address\":\"214.93.37.238\",\"date\":\"2015-10-05\",\"text\":\"Fusce lacus purus, aliquet at, feugiat non, pretium quis, lectus. Suspendisse potenti. In eleifend quam a odio. In hac habitasse platea dictumst. Maecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem.\"},
  {\"id\":\"222\",\"email\":\"karmstrong65@aol.com\",\"ip_address\":\"184.72.254.249\",\"date\":\"2015-10-04\",\"text\":\"Vivamus tortor. Duis mattis egestas metus. Aenean fermentum. Donec ut mauris eget massa tempor convallis. Nulla neque libero, convallis eget, eleifend luctus, ultricies eu, nibh.\"},
  {\"id\":\"358\",\"email\":\"rsims9x@jigsy.com\",\"ip_address\":\"85.190.76.246\",\"date\":\"2015-10-04\",\"text\":\"Praesent blandit. Nam nulla.\"}]
  }"}
  </code></pre>
  
  <p>Don't really know why the json starts with <code>mockup</code> instead of <code>data</code>.</p>
  
  <p>And I'm trying to get this AJAX to display the results:</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 : 'http://dashboard/ajaxtest',
                  dataType: "json",
                  method: 'post',
                  data: {
                     start : first,
                     limit : limit
                  },
                  success: function(data) {
                      flag = true;
                      $('#loader').hide();
                      if(data.count &gt; 0 ){
                          first = parseInt($('#first').val());
                          limit = parseInt($('#limit').val());
                          $('#first').val( first+limit );
                          $('#timeline-conatiner').append('&lt;h4&gt;'+date+' &lt;small&gt;'+email+'&lt;/small&gt;&lt;/h4&gt;');
                          $.each(data.content, function(key, value ){
                              html = '&lt;div class="content"&gt;';
                              html += '&lt;p&gt;'+value.text+'&lt;/p&gt;';
                              html += '&lt;/div&gt;';
                              $('#timeline-conatiner').append( html );
                          });
                      }else{
                          no_data = false;
                      $('#timeline-conatiner').append('No more data to show');
                      }
                  },
                  error: function( data ){
                      flag = true;
                      $('#loader').hide();
                      no_data = false;
                      // alert('Something went wrong, Please contact admin');
                      $('#timeline-conatiner').append('Something went wrong, Please contact admin');
                  }
              });
          }   
      }
  }); 
  </code></pre>
  
  <p>But the problems is it returns <code>No more data to show</code>. </p>
  
  <p>I have been troubleshooting </p>
  
  <ul>
  <li>and it seems as post is working. Changing the post values is showing 
  in Chrome dev.</li>
  <li>i can retrieve the (first) encoded json with var_dump</li>
  </ul>
  
  <p>So my guess is the AJAX</p>