I am not receiving the id from ajax in PHP, I have tried several forms but it always remains null, if in the file content.php I load the variable "$ post_id = 123" statically shows the data correctly.
I have my JS, where I get the id of a HTML select
function infodeptos(id) {
var parametros = {
"id" : id
};
$.ajax({
data: parametros,
url: '/wp-content/themes/brotec-wp/content.php',
type: 'post',
success: function (response) {
// console.log(response);
},
error: function(jqXHR, status, error) {
// Error handling
console.log(error);
}
});
}
and I have the content.php where I intend to get the id of the JS, load the variable $ post_id and pass it to HTML.
<?php
// post_id = 123, 126, 1
$post_id = 123;
// echo "post====>";
$id = $_POST['id'];
var_dump($id);
?>
<div class="info" id="info">
<ul>
<?php if(get_field('dormitorios',$post_id)): ?>
<li class="dormitorio"><?php the_field('dormitorios',$post_id); ?> dormitorios</li>
<?php endif; ?>
<?php if(get_field('banos',$post_id)): ?>
<li class="banos"><?php the_field('banos',$post_id); ?> baños</li>
<?php endif; ?>
<li class="sup-total"><strong>Sub. Total <br /><?php the_field('sub_total',$post_id); ?></strong></li>
<li class="item">Depto <br /><?php the_field('depto',$post_id); ?></li>
<li class="item">Terraza <br /><?php the_field('terraza',$post_id); ?></li>
<li class="sup-util"><strong>Sup.Útil <br /><?php the_field('sup_util',$post_id); ?></strong></li>
<li class="item">Depto <br /><?php the_field('depto2',$post_id); ?></li>
<li class="item">Terraza<br /><?php the_field('terraza2',$post_id); ?></li>
<li class="orientacion">Orientacion: <?php the_field('orientacion',$post_id); ?></li>
<li class="entrega">Entrega segundo semestre <?php the_field('entrega',$post_id); ?></li>
</ul>
<a class="cotizar" href="#">COTIZAR</a>
</div>
What am I doing wrong, or am I missing something, maybe in another way?