My view --
$(document).ready(function(){
$(".varsity").change(function(){
var id=$(this).val();
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/admin/get_varsity_faculty",
data:"varsity_id="+id,
dataType: 'json',
success: function(data)
{
alert(data);
}
});
});
});
My controller(admin)
public function get_varsity_faculty()
{
//admin controller
$varsity_id=$this->input->post('varsity_id');
$faculties=$this->admin_varsity->get_faculty_information($varsity_id);
//print_r($faculties);
echo json_encode($faculties);
}
when print_r($faculties) and alert response in my view (removing dataType:'json') get this output --
Array
(
[0] => Array
(
[unit_id] => 1
[vid] => 3
[unit_name] => Faculty of Civil Engineering
[form_starting_date] => 2013-05-15
[form_end_date] => 2013-05-22
[admission_date] => 2013-05-22
[possible_result_date] => 2013-05-22
[class_start_date] => 2013-05-21
[is_active] => 1
)
[1] => Array
(
[unit_id] => 2
[vid] => 3
[unit_name] => Faculty of Electrical & Electronic Engineering
[form_starting_date] => 0000-00-00
[form_end_date] => 0000-00-00
[admission_date] => 0000-00-00
[possible_result_date] => 0000-00-00
[class_start_date] => 0000-00-00
[is_active] => 1
)
[2] => Array
(
[unit_id] => 12
[vid] => 3
[unit_name] => Civil Engg
[form_starting_date] => 2013-06-11
[form_end_date] => 2013-06-12
[admission_date] => 2013-06-18
[possible_result_date] => 2013-06-04
[class_start_date] => 2013-06-10
[is_active] => 1
)
)
My model works really fine. BUT when I echo json_encode($faculties); with dataType:'json' in my view i am getting response like [object][object].And cant parse the response.I know its not a tough question.but i have tried so many times to overcome this myself.In a word my question is how can i get the json response and parse it form this array in my view. Thanks