Pass a string obtained with javascript to php

1

I have a processing Sketch embedded in an html, this through a JavaScript request, it gives me a string "serie=11&temp=22" , I need to send that to a php file within the same directory.

I can not get anything sent.

<!DOCTYPE html>
 <html>
 <head>
     <title>Hello Web - Accessing JavaScript from Processing</title>
     <script src="processing.js"></script>
     <script src="jquery-3.3.1.js"></script>
 </head>
 <body>
 <?php require 'prueba.php';?>
     <div id="msg">
     </div>
     <canvas data-processing-sources="sketch_180814b.pde"></canvas>
     <script type="application/javascript">
         var jsString = "Hello from JavaScript!";
         var yeah = "serie=11&temp=22";
         var printMessage = function (msg)
         {
             document.getElementById('msg').innerHTML = "Message: " + msg;
         }

     </script>

     <script type="application/javascript">

        var parametros = msg;
        $.ajax({
                data:   parametros, //datos que se envian a traves de ajax
                url:   'prueba.php', //archivo que recibe la peticion
                type:  'get', //método de envio
                beforeSend: function () {
                        $("#resultado").html("Procesando, espere por favor...");
                },
                success:  function (response) { //una vez que el archivo recibe el request lo procesa y lo devuelve
                        $("#resultado").html(response);
                }
        });
      }
     </script>
   </body>
   </html>




<?php

$enlace = mysqli_connect("localhost","root","");   
mysqli_select_db($enlace,"frigorifico");          
mysqli_query($enlace,"SET NAMES 'utf8'");

$serie = $_GET ['serie'];
$temperatura = $_GET ['temp'];

mysqli_query($enlace, "INSERT INTO 'datos' ('id', 'fecha', 'serie', 
'temperatura') VALUES (NULL, CURRENT_TIMESTAMP, '$serie', '$temperatura');" 
);

mysqli_close($enlace);

echo "datos ingresados correctamente";

?>
    
asked by Carlos Avila 16.08.2018 в 23:42
source

0 answers