[eluser]heaversm[/eluser]
Hi - I currently have a form setup that, depending on the user's dropdown selection, finds a specific table row, and returns that data back to a view as a JSON object. But how do I access that JSON Object's properties (columns of the table row)? Here's my code:
VIEW:
Code:
[removed]
$(document).ready(function() {
$('#f_treeindex').change(function(){
var tree_id = $('#f_treeindex').val();
if (tree_id != ""){
var post_url = "/index.php/control_form/get_tree/" + tree_id;
$.ajax({
type: "POST",
url: post_url,
success: function(tree)
{
alert (tree)
} //end success
}); //end AJAX
}//end if
}); //end change
}); //end docready
[removed]
CONTROLLER:
Code:
function get_tree($tree){
$this->load->model('Model_form','', TRUE);
header('Content-Type: application/x-json; charset=utf-8');
echo(json_encode($this->Model_form->get_tree_by_id($tree)));
}
MODEL:
Code:
function get_tree_by_id($tree = null){
$this->db->select('id, tree_name, tree_desc');
if($tree != NULL){
$this->db->where('id', $tree); //conditions
}
$query = $this->db->get('trees'); //db name
if($query->result()){
$tree_result = $query->row();
return $tree_result;
}
}