title: ajax get empty array from json_encode()
body: <p>So I have this php class where i have a function that get users from a PSQL database but the AJAX keep loging empty array in the console:</p>
  
  <pre><code>public function getUsers(){
          $query = pg_query(self::$DBH, "select id, name, email, admin from users order by name;");
          $result = array();
          $i = 0;
          while ($row = pg_fetch_row($query)) {
              $result[$i] = $row;
              $i++;
          }
          return $result;
      }
  </code></pre>
  
  <p>I use a phphandler file to call the function from ajax
  :</p>
  
  <pre><code>&lt;?php
      include_once $_SERVER['DOCUMENT_ROOT'].'/bdd.php';
      require_once 'modele_backend.php';
      $module = new Modele_Backend();
      echo json_encode($module -&gt; getUsers());
  
  
  
  ?&gt;
  </code></pre>
  
  <p>and finaly there is the AJAX call</p>
  
  <pre><code>$(document).ready(function(){
                  $("#user_email").on("input", function(){
                      // Print entered value in a div box
                      $.ajax({
                          url: 'modules/mod_backend/backendHandler.php',
                          type: 'post',
                          dataType: 'json',
                          success: function(response) { console.log(response); }
                      });
                  });
              });
  </code></pre>
  
  <p>The problem is that js keep showing empty array in the console.</p>
  
  <p>The json_encode works fine as json_last_error = 0.</p>
  
  <p>I Tried replacing the return of my getUsers() function by</p>
  
  <pre><code>echo json_encode($result);
  </code></pre>
  
  <p>to test if the function manage to encode my array and it did show up like a JSON on the page so this is not a encoding of my array problem. Still when AJAX get the result of the json_encode function it display an empty array.</p>
  
  <p>Thanks for any help !</p>
  
  <p>Necro.</p>