JSON error in PHP: SyntaxError: JSON.parse!

0

I have a problem filling out Google Maps with some markers, coming from a PHP (json).

When I open the browser, the error appears:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

PHP code:

<?
   header('Content-Type: application/json');
   header('Access-Control-Allow-Origin: *');

   include 'conn-login.php';

   if($_SERVER['REQUEST_METHOD'] == 'GET'){

     $sql = "SELECT id, lat, lng, endereco, especie, raca, obs, data, id_cadastro FROM mapa";
     $stmt = $mysqli->prepare($sql);
     $stmt->execute();
     $stmt->bind_result($id, $lat, $lng, $endereco, $especie, $raca, $obs, $data, $id_cadastro);
     $stmt->store_result();


   if($stmt->num_rows <= 0){

       $var = Array(
         'status' => 'ERRO',
         'msg' => 'Nenhum dado encontrado'
       );

     } else {

       while ($ln = $stmt->fetch()){

         $var = Array(
           'status' => 'OK',
           'id' => $id,
           'lat' => $lat,
           'lng' => $lng,
           'endereco' => $endereco,
           'especie' => $especie,
           'raca' => $raca,
           'obs' => $obs,
           'data' => $data,
           'id_cadastro' => $id_cadastro
         );

       };
     };

       echo json_encode($var);
       //var_dump($var);
       exit;


   }

   $stmt->close(); 

   ?>

And with this error, Google Maps can not pull the information. Could someone help me where I'm wrong?

    
asked by anonymous 24.04.2018 / 15:36

0 answers