$(document).ready(function () {
var click = $('.click');
click.on('click', function () {
var id = $(this).data('id');
usuario = '<?php $idMesero;?>';
for (var i = 1; i <= 14; i++) {
switch (id) {
case i:
//$('#' + id).addClass(presionado);
//time(id);
var request = $.ajax({
method: 'GET',
url: '../php/funciones.php', //el archivo server .php al que quieres enviar
data: {
dato: id,
user: usuario //dato que quieres enviar
},
dataType: 'json' //el tipo de dato tambien puede ser text
});
request.done(function (response) {
if (response.status) {
alert('Success: ' + response.result + "\n Message: " + response.message);
//window.location.href = '../php/ordena.php';
} else {
alert('Error: ' + response.message);
//window.location.href = window.location.href;
}
});
request.fail(function (jqXHR, textStatus) {
alert("Server request failed: " + textStatus);
//window.location.href = '';
});
break;
}
}
});
});
<?php
require 'conexion.php';
#require 'login.php';
require 'include/datosHamburguesas.php';
if(isset($_GET) && isset($_GET['dato'] && isset($_GET['usuario'])){
header('Content-Type: application/json');
$identificador = $_GET['dato'];
$usuario = $_GET['usuario'];
if($identificador == 1){
$inserta = "INSERT INTO $comanda (idComanda, idEmpleado, idProductos, fechaCom, noMesa, cantidadProd)
VALUES (3, $usuario, $idH, CURDATE(), 20, 1)";
$con->query($inserta);
echo json_encode(array(//pruebas si funciona imprimiendolo
'status' => 1,
'result' => $identificador,
'message' => "listo"
), true);
}
}
?>
I want to get a record from a table with ajax and then be able to pass it to another php file. I mean, in a table I have the id of a user and I want to retrieve it with ajax so that I can later use it in an insert, in another php file.
I tell you that you can do it with the post function, in the following example you pass the values to "example_ajax_process.php"
How about a session variable?
Suppose this is your first code where you retrieve the user id
Now you
INSERT
would be like thisI think it would be more practical to do it that way and you no longer fight with the FRONT
EDIT
I already saw the error, you are trying to retrieve a variable that does not exist
You can check in your PHP if you do
var_dump($GET);