I have a problem. I have to make an attendance report, based on the marking done by the employee at the time of entering, I must perform the assistance (if it is or is not). to insert the assistance, I need to do it through ajax but I could not.
this is my query code
$i=0;
$n=0;
while($fila=$consulta->fetch(PDO::FETCH_ASSOC))
{
$this->empleados[]=$filas;
$Filas = consult_cedula($fila['Persona']);
echo "<tr>";
echo '<td>' . $Filas['codsucursal'] . '</td>';
echo '<td>' . $fila['Persona'] . '</td>';
echo '<td>' . $fila['Fecha'] . '</td>';
echo '<td>' . $fila['Hora'] . '</td>';
echo '<td>' . $Filas['nombre'] . '</td>';
echo '<td>' . $Filas['cargo'] . '</td>';
echo '<td>' . '<input type="button" name="nom'.$n.'" id="btn'.$n.'" class="btn btn-danger" value="..." data-fech="' .
$fila['Fecha'] . '" data-hora="' . $fila['Hora'] . '" data-ced="' . $fila['Persona'] .
'" data-nom="' . $Filas['nombre'] . '" data-cargo="' . $Filas['cargo'] .'" onclick="myFunction('.$n.')">';
echo "</tr>";
$i=$i+1;
$n=$n+1;
}
this is my ajax code
function myFunction(valor){
var z = valor;
var connect, button, response, result;
var fech = $('#btn' + valor).data("fech");
var hora = $('#btn' + valor).data("hora");
var ced = $('#btn'+valor).data("ced");
var nom =$('#btn' + valor).data("nom");
var cargo = $('#btn' + valor).data("cargo")
var data = fech+hora+ced+nom+cargo;
console.log(data);
connect = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
connect.onreadystatechange = function() {
// ESTADO DE LA CONEXION
if(connect.readyState==4 && connect.status == 200) {
if(connect.responseText == 1) {
result = '<div class="alert alert-dismissible alert-success">';
result += '<button type="button" class="close" data-dismiss="alert">×</button>;'
result += '<h4 class="alert-heading">Registrando</h4>';
result += '<p> Estamos Procesando tu Registro </p>';
result += '</div>';
__('_AJAX_REG_').innerHTML = result;
location.reload();
} else {
__('_AJAX_REG_').innerHTML = connect.responseText;
}
} else if (connect.readyState!=4) {
result = '<div class="alert alert-dismissible alert-warning">';
result += '<button type="button" class="close" data-dismiss="alert">×</button>;'
result += '<h4 class="alert-heading">Procesando...</h4>';
result += '<p> Procesando Registro </p>';
result += '</div>';
__('_AJAX_REG_').innerHTML = result;
}
}
connect.open('POST','formatosTH/marcaje/ajax.php',true);
connect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
connect.send(data);
}
which redirects me to this file (which is ajax.php)
<?php
if($_POST) {
echo 1;
} else {
echo 'No hay nada';
}
?>
which I verify if something arrives by POST. but a NULL value arrives.
How could I solve it?