title: JSON_ENCODE converts all array values to string in AJAX Request
body: <p>I execute a simple AJAX Request, where i select some data from a mysql database. When i pass my Array back to Javascript, it always converts all Values in my Array into String, doesn't matter if its datatype was integer or boolean in my database.</p>
  
  <h1>EDIT:</h1>
  
  <p>I just found out, that MySQLi always converts datatypes to string, so I guess thats the problem. json_encode works fine.. <a href="https://stackoverflow.com/a/5323169/4720149">https://stackoverflow.com/a/5323169/4720149</a></p>
  
  <p><strong>SQL Statement</strong></p>
  
  <pre><code>   function getAll()
     {
          // Get all  buildings
          $db = new db();
  
          $sql = "SELECT * FROM building";
          $result = $db-&gt;runQuery($sql);
  
          $rows = array();
          while($row = $result-&gt;fetch_assoc()) {
              $rows[] = $row;
          }     
  
          return $rows;
     }  
  </code></pre>
  
  <p><strong>PHP Controller File</strong></p>
  
  <pre><code>function getBuildings(){
  
    $bu_db = new Building_Model();
    $buildings = $bu_db-&gt;getAll();
  
    echo json_encode($buildings);
  }
  </code></pre>
  
  <p><strong>Javascript file</strong></p>
  
  <pre><code>var data = {
    action: "getBuildings"
  };
  
  $.ajax({
    type: "POST",
    dataType: "json",
    url: "controller/Building.php",
    data: data,
    success: function(data) {
      console.log(data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
       console.log("Error in AJAX Request: " + textStatus + ", " + errorThrown);
    }
  });
  </code></pre>
  
  <p>Instead of keeping the original datatypes from the database, it turns all values into Strings:</p>
  
  <p><strong>Output</strong></p>
  
  <pre><code>[Object, Object, Object, Object, Obje...]
  &gt;0: Object
  &gt;1: Object
  &gt;2: Object
  &gt;3: Object
     ActiveCost: "20"
     BuildEfc: "0"
     BuildSfx: "0"
     BuildingEfc: "0"
     BuildingID: "1"
     Name: "Vogtei I"
     ResidentLvLNeeded: "0"
     ...
  </code></pre>
  
  <p>Does anybody know this problem?</p>
  
  <p>Thanks in Advance.</p>