I am hoping to be able to use .post method to send variables to a php file where I could be able to retrieve data from database with mysql query. So far I can send information about the variable using ajax but not able to retrieve output from the php script using ajax. I am very immature to ajax, hence learning through errors...Thanks for looking into my query.
How can I get to display php output within the div tag of index.php
test.php
<?php require('../config/connection.php'); ?>
<?php
$value = $_POST['value'];
$query = mysqli_query($dbc, "SELECT DISTINCT class,product FROM prdct_categories WHERE class = '$value'");
while($list = mysqli_fetch_assoc($query)){
$prdct = $list['product'];
echo $prdct;
}
?>
ajax code (index.php)
<div class="col-md-2" >
<?php
$test = $_GET['product'];
$q = "SELECT * FROM prdct_categories WHERE product = '$test' ";
$r = mysqli_query($dbc, $q);
$path_info = get_path();
$test1 = $path_info['call_parts'][1];
While($list = mysqli_fetch_assoc($r)) {?>
<li class="nav" <?php if($test1==$list['slugs']){echo'id="actives"';} ?>>
<a href="<?php echo $test;?>/<?php echo $list['slugs'];?> ">
<?php echo $list['subgroup']."(".$list['contains'].")".'<br/>';?></a></li>
<?php }?>
</div>
<div class="col-md-4" id="testing">
</div>
<script>
$(document).ready(function(){
$(".nav").click(function(){
$.post("test.php", {value:$(this).text()}, function(data) {$("#testing").text(data)} );
event.preventDefault();
});
});
</script>