Reputation: 29
I tired to try where is my fault .. please show me where is the mistake .. thank you
Controller
public function bulidSub()
{
$id_kategori = $this->uri->segment(3);
$data['sub_kategori']= $this->db->get_where('sub_kategori', array('id_kategori' => $id_kategori));
$output = null;
foreach ($data['sub_kategori']->result() as $row)
{
//here we build a dropdown item line for each query result
$output .= "<option value='".$row->id_sub_kategori."'>".$row->nama_sub_kategori."</option>";
}
echo $output;
}
<script type="text/javascript">
$(document).ready(function() {
$("#kategori").change(function(){
var id_kategori = $("select#kategori option:selected").attr('value');
/*dropdown post */
$.ajax({
url:"<?php echo base_url(); ?>/admin/buildSub/"+id_kategori,
type: "POST",
success: function(data){
$("#sub_kategori").html(data);
}
});//
});
});
</script>
Upvotes: 0
Views: 80
Reputation: 329
Test the output in browser by calling it directly instead of AJAX.
Function in PHP is bulidSub and you calling buildSub from AJAX. Also I'd use
buildSub($id_kategori = null) instead of $this->uri->segment(3)
Upvotes: 1
Reputation: 11984
This is not a valid syntax..
$data['sub_kategori']->result()
Change it to
$data['sub_kategori']->result
Upvotes: 0