Good I have an inconvenience with my code, I want to send you a data through ajax, that allows me to make a query according to what this variable brings, the problem is that you do not want to recognize me when making the $ _POST variable, in it I store the code of a Faculty and I want that according to the selected faculty I load the data, if someone can do me the favor of helping, it would be very helpful, thanks
Here is the code of my select
<div class="form-group">
<label for="selectFacultad" class="col-sm-1 control-label">Facultad:</label>
<div class="col-sm-4"><select name="codigoFacultad" id="selectFacultad" class="form-control" >
<option>Seleccione</option>
</select></div>
<button class="btn btn-primary fa fa-search" id="buscar" onclick="Cargar()"></button>
</div>
Now follow the escript where I have the function load ()
<script type="text/javascript">
function Cargar(){
var codigoFacultad = $('#selectFacultad').val();
alert(codigoFacultad);
$.ajax({
type: "POST",
dataType: "html",
url: "llenarPrograma.php",
data: codigoFacultad,
success: function(data){
$('#contenido').load('llenarPrograma.php');
}
});
}
</script>
Next the other file that should receive the variable
<?php
include_once("conexion.php");
ob_start();
mysqli_set_charset($conexion,"utf8");
$cod_facultad = $_POST['codigoFacultad']; //Esta es la variable que no me quiere recibir me sale indice indefinido
$consulta = mysqli_query($conexion, "SELECT id_programa,nombre_programa,duracion_semestral,horario,metodologia FROM programa WHERE id_facultad= '".$cod_facultad."'");
if (mysqli_num_rows($consulta) > 0)
{
echo "<table class='table table-bordered nowrap'>
<thead>
<tr>
<th>Codigo</th>
<th>Nombre</th>
<th>Duración semestral</th>
<th>Horario</th>
<th>Metodologia</th>
</tr>
</thead> ";
while($row = mysqli_fetch_array($consulta, MYSQL_ASSOC)) {
echo "<tr>";
echo "<td>".$row['id_programa']."</td>";
echo "<td>".$row['nombre_programa']."</td>";
echo "<td>".$row['duracion_semestral']."</td>";
echo "<td>".$row['horario']."</td>";
echo "<td>".$row['metodologia']."</td>";
echo "</tr>";
}
"</table>";
} else {
echo " <p>Aún no hay registros en la base de datos</p>";
}
?>