Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/04/2020, 17:35
santa2r
 
Fecha de Ingreso: diciembre-2008
Mensajes: 122
Antigüedad: 15 años, 5 meses
Puntos: 1
Pregunta Error con JSON, php y mysql al mostrar datos en tiempo real

Hola estoy intentando tomar datos de una DB en MySql que se encuentra en un archivo datossensor.php con JSON pero tengo dos errores y e intentado de todo y nada.

El codigo:

datossensor.php
Código PHP:
Ver original
  1. <?php
  2. header('Content-Type: application/json');
  3. $pdo=new PDO("mysql:dbname=admin_expertiot;host=expertosiot.ml","admin_expertiot","sim495975");
  4. switch($_GET['q']){
  5.         // Buscar Último Dato
  6.         case 1:
  7.           $statement=$pdo->prepare("SELECT data_temp FROM data ORDER BY data_id DESC LIMIT 0,1");
  8.             $statement->execute();
  9.             $results=$statement->fetchAll(PDO::FETCH_ASSOC);
  10.             $json=json_encode($results);
  11.             echo $json;
  12.         break;
  13.         // Buscar Todos los datos
  14.         default:
  15.  
  16.             $statement=$pdo->prepare("SELECT humedad,temperatura FROM tblsensores ORDER BY id ASC");
  17.             $statement->execute();
  18.             $results=$statement->fetchAll(PDO::FETCH_ASSOC);
  19.             $json=json_encode($results);
  20.             echo $json;
  21.         break;
  22.  
  23. }
  24. ?>

Codigo donde del archivo donde llamo a los datos.
Código Javascript:
Ver original
  1. setInterval(function() {
  2.   var JSON=$.ajax({
  3.                 url:"https://18.230.40.218/datossensor.php?q=1",
  4.                 dataType: 'json',
  5.                 async: false}).responseText;
  6.   var Respuesta = jQuery.parseJSON(JSON);
  7.     hand.showValue(Respuesta[0].data_temp, 1000, am4core.ease.cubicOut);
  8. }, 1000);

Los errores por consola son estos:

Código:
jquery.js:8630 GET https://18.230.40.218/datossensor.php?q=1 net::ERR_CERT_COMMON_NAME_INVALID
send	@	jquery.js:8630
ajax	@	jquery.js:8166
(anonymous)	@	dashboard-test.php:578
setInterval (async)		
(anonymous)	@	dashboard-test.php:577
e	@	core.js:1
Código:
Uncaught SyntaxError: Unexpected token u in JSON at position 0          VM8945:1 
    at JSON.parse (<anonymous>)
    at Function.jQuery.parseJSON (jquery.js:7522)
    at dashboard-test.php:582
jQuery.parseJSON @ jquery.js:7522
(anonymous) @ dashboard-test.php:582
setInterval (async)
(anonymous) @ dashboard-test.php:577
e @ core.js:1