I'm making several selects in my db and converting the results into an object, then I want to pass the variable to a js file but it's always an error. If I do json_encode() on the variable before sending it, the variable is empty, passing nothing to the js file. But if I remove json_encode() and make console.log() from the variable, Array () {[native code]} appears. When I was running on localhost it was working perfectly, but when I switched to the web hosting server it stopped working and started with errors. If anyone knows how I can solve this, I really appreciate it!
<!DOCTYPE html>
<?php
$numMax = 10; // numero de mesas do restaurante
$mysqli = new mysqli("***","***","***","***");
// Check connection
if ($mysqli -> connect_errno) {
  echo '<script type="text/javascript">console.log("Database failed")</script>';
  header("Refresh:0");
}
$sql = "SELECT * FROM ingredientes";
$i = 0;
if ($result = $mysqli -> query($sql)) {
  while ($obj = $result -> fetch_object()) {
    $ingredientes[$i]['id'] = $obj->id;
    $ingredientes[$i++]['nome'] = $obj->nome;
  }
  $result -> free_result();
}
$sql = "SELECT * FROM pratos";
$i = 0;
if ($result = $mysqli -> query($sql)) {
  while ($obj = $result -> fetch_object()) {
    $pratos[$i]['id'] = $obj->id;
    $pratos[$i]['idName'] = $obj->idName;
    $pratos[$i]['name'] = $obj->name;
    $pratos[$i]['path'] = $obj->path;
    $pratos[$i]['scale'] = $obj->scale;
    $pratos[$i]['escolhido'] = $obj->escolhido;
    $pratos[$i++]['preco'] = $obj->preco;
  }
  $result -> free_result();
}
$sql = "SELECT * FROM prato_ingredientes";
$i = 0;
if ($result = $mysqli-> query($sql)) {
  while ($obj = $result -> fetch_object()) {
    $prato_ingredientes[$i]['idPrato'] = $obj->idPrato;
    $prato_ingredientes[$i++]['idIngredientes'] = $obj->idIngredientes;
  }
  $result -> free_result();
}
$resultado['ingredientes'] = $ingredientes;
$resultado['pratos'] = $pratos;
$resultado['prato_ingredientes'] = $prato_ingredientes;
mysqli_close($mysqli);
?>
<html lang="en">
  <head>
    <link rel="apple-touch-icon" href="./imagens/dimmersions_logo.png">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <title>AR Food</title>
    <script src="https://hammerjs.github.io/dist/hammer.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://aframe.io/releases/0.9.2/aframe.min.js"></script>
    <script src="https://raw.githack.com/jeromeetienne/AR.js/2.0.5/aframe/build/aframe-ar.js"></script>
    <script src="scripts/localforage.js" charset="utf-8"></script>
    <script src="scripts/lodash.js" charset="utf-8"></script>
    <script type="text/javascript">var resultado = '<?= json_encode($resultado); ?>';</script>
    <script src="scripts/scriptIndex.js" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="./style.css">
  </head>
  <body id="body">
    <?php echo json_last_error_msg();  ?>
    <div id="mesaDiv">
      <p class="order">Table Number</p>
      <select class="formMesa" id="mesaId">
        <?php
          for ($i=1; $i <= $numMax; $i++) {
            echo "<option value='".$i."'>".$i."</option>";
          }
        ?>
      </select>
      <button type="button" class="myButton" id="start">Start</button>
    </div>
    <div class="deletePrato"></div>
    <div id="ordersDiv">
      <p class="close" id="closeOrders">X</p>
      <div id="orderButton">
        <p class="order">Order</p>
      </div>
    </div>
    <div id="escondido" hidden="true">
      <div id="swiper"></div>
      <div id="orderDiv">
        <p class="order">Order</p>
      </div>
      <div id="tituloDiv">
        <p id="nameFood"></p>
      </div>
      <img id="loadingGif" alt="loadingGif" src="./imagens/load.gif">
      <div id="swipeDiv">
        <img id="swipeImg" alt="swipeImg" src="./imagens/swipe.png">
        <p id="swipe">Swipe for next dish</p>
      </div>
      <div id="ingredientesBar">
        <p id="seta">↑</p>
        <p id="ingredientesSwipe">Ingredients</p>
      </div>
      <div id="ingredientsDiv" hidden="true">
        <p class="close" id="closeIngredientes">X</p>
        <ul style="padding: 1em 3em" id="ulIngredientes">
        </ul>
      </div>
    </div>
    <div id="markerInicial">
      <img id="markerOpacidade" alt="markerOpacidade" src="./imagens/pattern-restaurant-menu.png">
      <p id="markerTitulo">Please point to the marker</p>
    </div>
    <a-scene arjs='trackingMethod: best; sourceWidth:1280; sourceHeight:960; debugUIEnabled:false' embedded vr-mode-ui="enabled: false">
      <a-assets id="assets">
      </a-assets>
      <a-marker detect-marker id="marker" preset='custom' type='pattern' url='./markers/pattern-restaurant-menu.patt' smooth="true">
      </a-marker>
      <a-entity camera></a-entity>
    </a-scene>
  </body>
</html>
<script type="text/javascript">var resultado =<?= json_encode($resultado); ?>;</script>
Data output
array (
  'ingredientes' => 
  array (
    0 => 
    array (
      'id' => '1',
      'nome' => 'A�ucar',
    ),
    1 => 
    array (
      'id' => '2',
      'nome' => 'Sal',
    ),
    2 => 
    array (
      'id' => '3',
      'nome' => 'Farinha',
    ),
    3 => 
    array (
      'id' => '4',
      'nome' => 'Fermento',
    ),
    4 => 
    array (
      'id' => '5',
      'nome' => 'Lactic�nios',
    ),
    5 => 
    array (
      'id' => '6',
      'nome' => 'Leite',
    ),
    6 => 
    array (
      'id' => '7',
      'nome' => 'Fruta',
    ),
    7 => 
    array (
      'id' => '8',
      'nome' => 'Manteiga',
    ),
    8 => 
    array (
      'id' => '9',
      'nome' => 'Cebola',
    ),
    9 => 
    array (
      'id' => '10',
      'nome' => 'Ovo',
    ),
    10 => 
    array (
      'id' => '11',
      'nome' => 'Nata',
    ),
    11 => 
    array (
      'id' => '12',
      'nome' => 'Chocolate',
    ),
    12 => 
    array (
      'id' => '13',
      'nome' => 'Alho',
    ),
    13 => 
    array (
      'id' => '14',
      'nome' => 'Cenoura',
    ),
    14 => 
    array (
      'id' => '15',
      'nome' => 'Peixe',
    ),
    15 => 
    array (
      'id' => '16',
      'nome' => 'Canela',
    ),
    16 => 
    array (
      'id' => '17',
      'nome' => 'Pimenta',
    ),
    17 => 
    array (
      'id' => '18',
      'nome' => 'Salsa',
    ),
    18 => 
    array (
      'id' => '19',
      'nome' => 'Or�g�os',
    ),
    19 => 
    array (
      'id' => '20',
      'nome' => 'Piment�o',
    ),
  ),
  'pratos' => 
  array (
    0 => 
    array (
      'id' => '1',
      'idName' => 'sushi',
      'name' => 'Sushi',
      'path' => './modelos/sushi/scene.gltf',
      'scale' => '0.1 0.1 0.1',
      'escolhido' => '0',
      'preco' => '24.69',
    ),
    1 => 
    array (
      'id' => '2',
      'idName' => 'burger',
      'name' => 'Chicken Burger',
      'path' => './modelos/chicken_burger/scene.gltf',
      'scale' => '0.12 0.12 0.12',
      'escolhido' => '0',
      'preco' => '4.84',
    ),
    2 => 
    array (
      'id' => '3',
      'idName' => 'donut',
      'name' => 'Donut',
      'path' => './modelos/donut/scene.gltf',
      'scale' => '0.4 0.4 0.4',
      'escolhido' => '1',
      'preco' => '2.5',
    ),
    3 => 
    array (
      'id' => '4',
      'idName' => 'sobremesa',
      'name' => 'Milk Pie',
      'path' => './modelos/sobremesa/scene.gltf',
      'scale' => '0.08 0.08 0.08',
      'escolhido' => '0',
      'preco' => '7.49',
    ),
    4 => 
    array (
      'id' => '5',
      'idName' => 'boloC',
      'name' => 'Chocolate Cake',
      'path' => './modelos/bolo_chocolate/scene.gltf',
      'scale' => '0.08 0.08 0.08',
      'escolhido' => '0',
      'preco' => '2',
    ),
    5 => 
    array (
      'id' => '6',
      'idName' => 'boloFV',
      'name' => 'Red Fruit Cake',
      'path' => './modelos/bolo_frutos_vermelhos/scene.gltf',
      'scale' => '0.04 0.04 0.04',
      'escolhido' => '0',
      'preco' => '2.5',
    ),
  ),
  'prato_ingredientes' => 
  array (
    0 => 
    array (
      'idPrato' => '5',
      'idIngredientes' => '12',
    ),
    1 => 
    array (
      'idPrato' => '5',
      'idIngredientes' => '4',
    ),
    2 => 
    array (
      'idPrato' => '5',
      'idIngredientes' => '1',
    ),
    3 => 
    array (
      'idPrato' => '5',
      'idIngredientes' => '3',
    ),
    4 => 
    array (
      'idPrato' => '5',
      'idIngredientes' => '10',
    ),
    5 => 
    array (
      'idPrato' => '5',
      'idIngredientes' => '6',
    ),
    6 => 
    array (
      'idPrato' => '6',
      'idIngredientes' => '1',
    ),
    7 => 
    array (
      'idPrato' => '6',
      'idIngredientes' => '3',
    ),
    8 => 
    array (
      'idPrato' => '6',
      'idIngredientes' => '4',
    ),
    9 => 
    array (
      'idPrato' => '6',
      'idIngredientes' => '6',
    ),
    10 => 
    array (
      'idPrato' => '6',
      'idIngredientes' => '7',
    ),
    11 => 
    array (
      'idPrato' => '2',
      'idIngredientes' => '2',
    ),
    12 => 
    array (
      'idPrato' => '2',
      'idIngredientes' => '3',
    ),
    13 => 
    array (
      'idPrato' => '2',
      'idIngredientes' => '4',
    ),
    14 => 
    array (
      'idPrato' => '2',
      'idIngredientes' => '10',
    ),
    15 => 
    array (
      'idPrato' => '2',
      'idIngredientes' => '12',
    ),
    16 => 
    array (
      'idPrato' => '2',
      'idIngredientes' => '14',
    ),
    17 => 
    array (
      'idPrato' => '2',
      'idIngredientes' => '20',
    ),
    18 => 
    array (
      'idPrato' => '4',
      'idIngredientes' => '1',
    ),
    19 => 
    array (
      'idPrato' => '4',
      'idIngredientes' => '5',
    ),
    20 => 
    array (
      'idPrato' => '4',
      'idIngredientes' => '7',
    ),
    21 => 
    array (
      'idPrato' => '4',
      'idIngredientes' => '11',
    ),
    22 => 
    array (
      'idPrato' => '4',
      'idIngredientes' => '16',
    ),
    23 => 
    array (
      'idPrato' => '1',
      'idIngredientes' => '3',
    ),
    24 => 
    array (
      'idPrato' => '1',
      'idIngredientes' => '5',
    ),
    25 => 
    array (
      'idPrato' => '1',
      'idIngredientes' => '7',
    ),
    26 => 
    array (
      'idPrato' => '1',
      'idIngredientes' => '10',
    ),
    27 => 
    array (
      'idPrato' => '1',
      'idIngredientes' => '13',
    ),
    28 => 
    array (
      'idPrato' => '1',
      'idIngredientes' => '15',
    ),
    29 => 
    array (
      'idPrato' => '1',
      'idIngredientes' => '18',
    ),
    30 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '2',
    ),
    31 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '3',
    ),
    32 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '4',
    ),
    33 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '8',
    ),
    34 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '10',
    ),
    35 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '11',
    ),
    36 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '12',
    ),
    37 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '13',
    ),
    38 => 
    array (
      'idPrato' => '20',
      'idIngredientes' => '18',
    ),
    39 => 
    array (
      'idPrato' => '3',
      'idIngredientes' => '1',
    ),
    40 => 
    array (
      'idPrato' => '3',
      'idIngredientes' => '3',
    ),
    41 => 
    array (
      'idPrato' => '3',
      'idIngredientes' => '4',
    ),
    42 => 
    array (
      'idPrato' => '3',
      'idIngredientes' => '8',
    ),
    43 => 
    array (
      'idPrato' => '3',
      'idIngredientes' => '9',
    ),
    44 => 
    array (
      'idPrato' => '3',
      'idIngredientes' => '12',
    ),
  ),
)
You are giving an error in the special characters which before in localhost did not happen
