Estoy pasando un parámetro a PHP para recuperar un contenido concreto usando radio buttons con name="id_estructura". Para ello utilizo el siguiente script:
<div id="modelo"></div>
<script async language="javascript">
$(document).ready(function(){
$("input[name='id_estructura']").change(function(){
var xhttp = new XMLHttpRequest();
elegido=$(this).val();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("modelo").innerHTML =
this.responseText;
}
};
xhttp.open("POST", "index.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send ("elegido="+elegido);
});
});
</script>
Que luego recojo con esta función en PHP y muestro en el div "modelo".
$idEstructuraInstant = filter_input(INPUT_POST, 'elegido');
if(isset($idEstructuraInstant)){
ChromePhp::log($idEstructuraInstant);//debug
$resulEstilos = Estilos::consultaSinFormato($idEstructuraInstant);
$bucle_Estilos = $resulEstilos[0];
$cont_Estilos=0;
$contadorEstilos = count($bucle_Estilos);
foreach($bucle_Estilos as $itemEstilos):
if($contadorEstilos!=''){
echo '<div>CONTENIDO</div>';
}
endforeach;
}
Todo funciona bien, el problema es que además del parámetro me devuelve todo el código HTML de la página parent tal y como se ve en la captura adjunta. Alguien sabe por qué?