i want to fetch 1st category data in category div and subcategory data in sub-cat div. i am using Ajax , Jquery. i have tried below code but result shows undefined. Please let me know where the code is wrong ?
HTML is :
<body class="bg-color">
<div id="page-wrap">
<div class="border-radius">
<div class="box-heading">Assignment</div>
<div class="footer group">
<div id="category">
5
</div>
<div id="sub-cat">
5
</div>
<div id="sub-cat1">
5
</div>
</div>
</div>
</div>
</div>
</body>
Javascript is :
<script type="text/javascript">
$(document).ready(function(){
});
function pageLoad()
{
var result = new Array();
$.ajax({
type: "POST",
url: "get.php",
data: "",
async: false
}).responseText.split(",");
document.getElementById('category').innerHTML = result[0];
}
window.onload = pageLoad;
</script>
PHP code is
<?php
require("_assets/config/dbc.php");
$id = $_REQUEST['id'];
$query = mysql_query("SELECT * FROM category");
while($row = mysql_fetch_array($query)){
$a = '<a href="javascript:void(0);" onClick="vote1(' . $row['cat_id'] . ');">' .$row['title'] . '</a></p>';
}
$query1 = mysql_query("SELECT * FROM subcategory");
while($row1 = mysql_fetch_array($query1)){
$b = '<a href="javascript:void(0);" onClick="vote1(' . $row1['cat_id'] . ');">' .$row1['title'] . '</a></p>';
}
echo $result = $a."*".$b;
?>
Actually i want when the page is load ajax go to get.php file and get category by ID , sub category by id and sub sub category by ID. so i will show these on my 3 divs.. Please sort out my this problem..